网站设置关键字,如何创立一个公众号,个人发布信息免费推广平台,重庆搜索引擎推广问题#xff1a;使用js动态添加的元素#xff0c;给该元素绑定了点击事件#xff0c;在PC端一切正常触发#xff0c;但是在移动端却无法触发方法。
原因#xff1a;在移动端,绑定点击事件需要注意使用 touch 事件,而不是鼠标的 click 事件。 常用的触摸事件有:- touchsta…问题使用js动态添加的元素给该元素绑定了点击事件在PC端一切正常触发但是在移动端却无法触发方法。
原因在移动端,绑定点击事件需要注意使用 touch 事件,而不是鼠标的 click 事件。 常用的触摸事件有:- touchstart:手指触摸屏幕时触发 - touchmove:手指滑动屏幕时连续触发 - touchend:手指离开屏幕时触发 - 避免使用click事件,这是为鼠标设计的 - 对于触屏设备,要区分不同手指的触摸事件 - 可以同时绑定touch和click事件,实现移动端和PC端的兼容 // 方法一:通过addEventListener绑定
element.addEventListener(touchstart, function(){//点击处理
}, false); // 方法二:直接内联绑定
div ontouchstarttouch(event)/div function touch(event) {// 点击处理
} 蜂鸟视图的室内地图动态添加的DomMarker无法在移动端进行点击触发的解决方法 // 显示选择起点终点的选项卡function showDomMarker(position) {if (domMarker) {domMarker.remove();domMarker null;}domMarker new fengmap.FMDomMarker({x: position.x,y: position.y,domHeight: 80,domWidth: 200,anchor: fengmap.FMMarkerAnchor.BOTTOM,content: div style display: inline-block; width: 200px; text-align: center;div styledisplay: flex;margin-bottom: 10px; border-radius: 6px; background-color: white; text-align: center;span idclickStart styleflex: 1; height: 30px; color: white;padding: 10px 16px; line-height: 30px; background-color: #2F65EE; border-bottom-left-radius: 6px; border-top-left-radius:6px; onclicksetStart() ontouchstartsetStart()作为起点/spanspan styleflex: 1; height: 30px; padding: 10px 16px; line-height: 30px; onclicksetEnd() ontouchstartsetEnd()作为终点/span/divdiv stylebackground-image: url(https://developer.fengmap.com/fmAPI/images/navi/marker.png);display: inline-block; width: 32px; height: 32px;background-size:100%;/div/div,});var level position.level;var floor map.getFloor(level);domMarker.addTo(floor);}