jQuery mouseup事件是否适用于触控设备?
我找不到任何答案,所以我在这里问。 目前我没有任何触摸设备,所以我无法测试它。
如果在容器外部单击,则以下代码会隐藏容器中的所有子容器。
$(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
是否相同?
不,它不起作用。 但这是一个touchstart
和touchend
事件。
$(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(); } });