有没有一种方法可以使触摸启动事件不会触发点击事件

Is there a way that a touch start event will not trigger the click event?

本文关键字:事件 启动 触摸 一种 可以使 方法 有没有      更新时间:2023-09-26

当访问者点击图像时,将触发click事件。然而,当有人触摸图像时,即使touchstart事件也可用,也会触发相同的click事件。

我喜欢实际点击(鼠标)事件和触摸事件的不同行为。奇怪的是,在智能手机上使用时,甚至会触发mouseup事件。你有没有办法把鼠标和触摸事件分开?

event.preventDefault();

成功了,希望这能帮助到人们!

您可以规范化事件。。

看看我对这个问题的回答:

点击事件在iPad 中的触摸端调用两次

您也可以在jQuery移动源代码中查找灵感:http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.js从982 线开始

/* 
* "events" plugin - Handles events
*/
(function( $, window, undefined ) {
// add new event shortcuts
$.each( ( "touchstart touchmove touchend orientationchange throttledresize " +
                    "tap taphold swipe swipeleft swiperight scrollstart scrollstop" ).split( " " ), function( i, name ) {
    $.fn[ name ] = function( fn ) {
        return fn ? this.bind( name, fn ) : this.trigger( name );
    };
    $.attrFn[ name ] = true;
});
....

查看点击事件:(第1049行)

$.event.special.tap = {

这是一种防止触摸启动后点击的复杂方法。在触摸启动后传播的点击称为重影点击。

谷歌已经实施了一个解决方案。给你。。

http://code.google.com/mobile/articles/fast_buttons.html#ghost