jQuery mouseup事件可在触摸设备上使用吗? [英] Does jQuery mouseup event work on touch devices?
本文介绍了jQuery mouseup事件可在触摸设备上使用吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我找不到任何答案,所以我在这里问.目前,我没有任何触摸设备,因此无法对其进行测试.
I couldn't find any answer so I'm asking here. Currently I don't own any touch devices so I can't test it.
如果在容器中单击以下代码,则以下代码会将所有子容器隐藏在容器中.
The following code hides all subcontainers in a container if clicked outside of it.
$(document).mouseup(function(e) {
var container = $('#container');
if (!container.is(e.target) // if the target of the click isn't the container...
&& container.has(e.target).length === 0) // ... nor a descendant of the container
{
$('.subcontainer').hide();
}
});
这在触摸设备上起作用吗?或者在触摸设备上有与mouseup
等效的内容吗?
Does this work on touch devices or there is any equivalent of mouseup
for touch devices?
推荐答案
不,它不起作用.但是这是一个touchstart
和touchend
事件.
No, it does not work. But here is a touchstart
and touchend
event.
$(document).bind( "mouseup touchend", function(e){
var container = $('#container');
if (!container.is(e.target) // if the target of the click isn't the container...
&& container.has(e.target).length === 0) // ... nor a descendant of the container
{
$('.subcontainer').hide();
}
});
这篇关于jQuery mouseup事件可在触摸设备上使用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文