Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 单击或触摸特定容器外部时_Jquery_Mobile_Touch_Containers - Fatal编程技术网

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库的触摸事件


谢谢。

你的意思是喜欢这条评论上的解决方案吗?哇,是的,完全一样!非常感谢!可能重复的