jQuery mouseout on iPad

jQuery mouseout on iPad

本文关键字:iPad on mouseout jQuery      更新时间:2023-09-26

我有一个在桌面浏览器上完美工作的jQuery代码;

$("span#checkbox_err").mouseout(function () {
                        $("span#checkbox_err").fadeOut("slow");
                    });

但是同样的情况在iPad上不会触发(结果checkbox_err显示在屏幕上,但从不隐藏)

如何在iPad上触发mouseout事件?

我也想避免使用任何额外的库只是为了解决这个小问题…

我有一个后续问题

我正在iPad上测试一个页面,并且在执行鼠标退出行为时遇到了一些问题。

所以这个问题很容易理解;1. 在我的页面上,点击(或者说是触摸)上有一个复选框,我想显示一个errorMsg 2。在点击/触摸errorMsg以外的任何东西时,我想隐藏errorMsg

下面是我写的代码;

$(document).bind("touchstart",function(e){
         if(e.target.id != "checkbox_err")
        $("span#checkbox_err").fadeOut("slow");
     });
}

$("input:checkbox").bind("touchstart",function(){
$("span#checkbox_err").fadeIn("fast");
});

现在的问题是,当我点击/触摸复选框,errorMsg显示了一段时间,然后它也隐藏了它立即(因为目标不是errorMsg)

如何解决这个问题?

你可以尝试用。blur()代替。mouseout()

可能是因为冒泡?这对我来说是有意义的,事件将到达底层,而不是目标。所以你必须停止eventPropagation:

$("input:checkbox").bind("touchstart",function(){
$("span#checkbox_err").fadeIn("fast");
event.stopPropagation.
});

希望对你有帮助。你有没有碰巧找到鼠标离开的替代方法?

这个例子一定会对你有所帮助!http://jsfiddle.net/PzTcS/12/,在iPad上运行良好。

您可以尝试在ipad

中使用GestureEnd()事件