我想在ipad /移动设备上点击div时显示/隐藏元素。我使用过touchstart和touchend活动。但是,我想停止div元素的touchend事件' .view-list'以便' .viewlist-popup'不会立即隐藏。
<div class="view-list">VIEW LIST
<div class="viewlist-popup">
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
</div>
</div>
$('.view-list').bind('touchstart', function() {
$(this).find('.viewlist-popup').show();
});
$(document).bind('touchend', function() {
$('.view-list').find('.viewlist-popup').hide();
});
答案 0 :(得分:0)
您应该按事件目标过滤它:
$(document).bind('touchend', function(e) {
if($(e.target).hasClass('view-list')) return;
$('.view-list').find('.viewlist-popup').hide();
});
如果你不想在触及任何后代时隐藏它:
if($(e.target).closest('.view-list').length) return;