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

mac2022-06-30  21

  

<div id="showSelectOptions" style="width: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

最新回复(0)