码迷,mamicode.com
首页 > Web开发 > 详细

点击除元素以外的任意地方隐藏元素js

时间:2017-05-17 19:14:24      阅读:261      评论:0      收藏:0      [点我收藏+]

标签:callee   log   func   其他   .com   eve   argument   on()   amp   

比如想实现点击列表弹出筛选器,点击其他任意地方关闭筛选器,如图

技术分享

 

该筛选器class名

 1  $(document).click(function () {
 2       $(".subMenu").hide();
 3 });
 4  $(".subMenu").on("click", function (event) {
 5       //取消事件冒泡
 6       var e = arguments.callee.caller.arguments[0] || event; //若省略此句,下面的e改为event,IE运行可以,但是其他浏览器就不兼容
 7       if (e && e.stopPropagation) {
 8           // this code is for Mozilla and Opera
 9           e.stopPropagation();
10       } else if (window.event) {
11           // this code is for IE
12           window.event.cancelBubble = true;
13       }
14 });

首先点击document任意位置隐藏该元素,然后给该元素绑定click事件,阻止冒泡到该元素,则可以顺利实现需求。

 

点击除元素以外的任意地方隐藏元素js

标签:callee   log   func   其他   .com   eve   argument   on()   amp   

原文地址:http://www.cnblogs.com/beileixinqing/p/6868969.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!