繁体   English   中英

在IE11中使用指针事件时阻止单击?

[英]Prevent click when using pointer events in IE11?

我正在开发一个必须在IE11和Edge上运行的JavaScript应用程序。 在IE11中,我看到的事件链(从https://patrickhlauke.github.io/touch/tests/results/复制)如下:

指针> mouseover> pointerenter> mouseenter> pointerdown> mousedown>(pointermove> mousemove)+> pointerup> mouseup>(lostpointercapture)> pointerout> mouseout> pointerleave> mouseleave> focus> click

该应用程序已经连线处理鼠标和触摸事件,所以我在所有指针事件上调用preventDefault()来取消相应的鼠标事件。 不幸的是,点击在结束时出现并导致问题。 有没有内置的方法来禁止点击事件在最后解雇?

我正在使用jQuery指针事件Polyfill( https://github.com/jquery/PEP )在Webkit浏览器上使用“pointerup”事件,我遇到了类似的问题。 就我而言,我不得不阻止链接被跟踪。

我通过在“pointerup”触发后立即添加“click”事件侦听器来解决问题,然后阻止“click”事件并删除其侦听器。 像这样:

var myLink = document.getElementsByClassName("myLink")[0];

myLink.addEventListener("pointerup", handleLinkPress);

function handleLinkPress(evt) {
    // do something here...

    evt.target.addEventListener("click", unfollowLink);

    function unfollowLink(evt) {
        evt.preventDefault();
        evt.target.removeEventListener("click", unfollowLink);
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM