Javascript/jQuery-在iPhone的元素外部点击 [英] Javascript / jQuery - Tap outside an element on an iPhone
本文介绍了Javascript/jQuery-在iPhone的元素外部点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
关于此问题,我发现了一个很好的答案,可以检测到div之外的点击:
I found a great answer on detecting a click outside a div from this question: How do I detect a click outside an element?, which works fantastically.
但是我注意到,如果我在元素外部点击,则在测试我的网站时,它在iPhone上无法正常工作.
But I've noticed that it doesn't work on the iPhone when testing my site, if I tap outside the element.
这是代码(直接从该答案中获取)
Here is the code (taken directly from that answer)
$('html').click(function() {
//Hide the menus if visible
});
$('#menucontainer').click(function(event){
event.stopPropagation();
});
推荐答案
这对我有用:)
$('html').on('touchstart', function(e) {
$('.navbar-flyout').hide();
})
$(".navbar-flyout").on('touchstart',function(e) {
e.stopPropagation();
});
这篇关于Javascript/jQuery-在iPhone的元素外部点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文