触点端再次触点启动

Touchend fires on touchstart second time around

本文关键字:触点 启动      更新时间:2023-09-26

有人知道为什么touchend事件会在touchstart事件期间触发吗?这只会在第二次出现。

一个快速代码片段:

function touchstart (event) {
    $(event.target).one('touchend', function () {
        alert('fired');
    }
}

这是第一次触发,它工作得很好。第二次触发touchstart的警报

http://jsfiddle.net/8SVFR/

编辑:

看起来这可能只是iPhone的问题

原来…在触端事件中触发警报会导致各种问题。当你点击'ok'它会触发touchstart所以touchend会在下次你触摸元素时被触发。幸运的是,我使用警报来检查我的代码-所以一旦它被删除,我的代码工作完美!

将"touchend"处理程序的代码放在setTimeout中,设置为0ms。这样的:

$(someElement).on("touchend",
function(){
    setTimeout(function(){
    /*Your code*/
    }, 0);
});