- a标签在促发touchend事件时,a标签就会跳转;
- touchmove最终也会触发touchend,所以会导致误触;
代码显示
// 全面禁止移动端事件的默认行为
document.addEventListener('touchstart',function(ev){
ev = ev || event;
ev.preventDefault();
})
// 获取页面中所有的a标签
var aNodes = document.querySelectorAll('a');
for(var i=0;i<aNodes.length;i++){
aNodes[i].addEventListenner('touchstart',function(){
this.Ismoved = false;
})
aNodes[i].addEventListenner('touchmove',function(){
this.Ismoved = true;
})
aNodes[i].addEventListenner('touchend',function(){
if(!Ismoved){
location.href = this.href;
}
})
}