Jquery 单击或触摸特定容器外部时
我试图在单击或触摸容器外部时关闭特定元素 我知道这不管用,但你知道:Jquery 单击或触摸特定容器外部时,jquery,mobile,touch,containers,Jquery,Mobile,Touch,Containers,我试图在单击或触摸容器外部时关闭特定元素 我知道这不管用,但你知道: $(document).on('touch', 'click', function (e) { var container = $('.sidebar'); if (!container.is(e.target) // if the target of the click isn't the container... && container.has(e.target).len
$(document).on('touch', 'click', function (e) {
var container = $('.sidebar');
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
{
$('body').removeClass('sidebar-opened');
}
});
我怎么做才能正确呢?我正在使用jQuery移动UI库的触摸事件
谢谢。你的意思是喜欢这条评论上的解决方案吗?哇,是的,完全一样!非常感谢!可能重复的