JQuery 点击div外的地方隐藏该div。。。

发布于 2015-03-09  644 次阅读


.pop { width:200px; height:130px; background:#080;}

 $(function(){

    $(document).bind("click",function(e){

    var target = $(e.target);

    if(target.closest(".pop").length == 0){

    $(".pop").hide();

    }

    })

    })

class="bigPic"的div是被显示或隐藏的div,另外.case > ul > li是class="bigPic"的父级元素

    $("body").bind("click",function(evt){

    if($(evt.target).parents(".case > ul > li").length==0)

    {

    $('.bigPic').hide();

    }

    });

最后更新于 2000-01-01