js点击空白关闭弹出层

[javascript]  view plain  copy
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  2. <html xmlns="http://www.w3.org/1999/xhtml">  
  3. <head>  
  4. <title>点击空白处关闭弹出层</title>  
  5. <meta http-equiv="content-type" content="text/html;charset=gb2312">  
  6. <style type="text/css">  
  7. #box{width:300px;height:200px;border:1px solid #000;display:none;}  
  8. .btn{color:red;}  
  9. </style>  
  10. <script src="/ajaxjs/jquery1.3.2.js" type="text/javascript"></script>  
  11. <script type="text/javascript">  
  12. $(function(){  
  13.     $(".btn").click(function(event){  
  14.         var e=window.event || event;  
  15.         if(e.stopPropagation){  
  16.             e.stopPropagation();  
  17.         }else{  
  18.             e.cancelBubble = true;  
  19.         }     
  20.         $("#box").show();  
  21.     });  
  22.     $("#box").click(function(event){  
  23.         var e=window.event || event;  
  24.         if(e.stopPropagation){  
  25.             e.stopPropagation();  
  26.         }else{  
  27.             e.cancelBubble = true;  
  28.         }  
  29.     });  
  30.     document.onclick = function(){  
  31.         $("#box").hide();  
  32.     };  
  33. })  
  34. </script>  
  35. </head>  
  36. <body>  
  37. <div id="box"></div>  
  38. <span class="btn">点击此处打开弹出层</span><br>点击空白处关闭弹出层  
  39. </body>  
  40. </html>  
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值