4

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.

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();
});
4

2 回答 2

11

这对我有用:)

$('html').on('touchstart', function(e) {
    $('.navbar-flyout').hide();
})
$(".navbar-flyout").on('touchstart',function(e) {
    e.stopPropagation();
});
于 2013-03-27T15:03:24.063 回答
3
var doc = document.documentElement;
doc.addEventListener('click', function (e) { //TODO();});

诀窍:

/*Add this line into only mobile css*/
body{cursor:pointer}
于 2015-05-31T20:40:04.357 回答