<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