工作随笔记 点击除div自身之外的地方,关闭自己

  

<div id="showSelectOptions" style="100px;height:100px;background-color:red;border:1px solid; ">点击除我之外的地方,关闭我!^_^</div>

jquery 实现代码:

    //绑定div之外的点击事件
    $(document).bind("click", function (e) {
        var target = $(e.target);
        if (target.closest("#showSelectOptions").length == 0 ) {
            $("#showSelectOptions").hide();
        }
    });

原文地址:https://www.cnblogs.com/mzws/p/3247369.html