html实现网站全局按钮点击后置灰,不允许连续点击

 1 <script>
 2     document.addEventListener("mouseup", upHandler, true);
 3     function upHandler(e){
 4         var target=undefined;
 5         //元素类型即BUTTON
 6         if(e.target.tagName=='BUTTON'||(e.target.type!=undefined&&e.target.type.toUpperCase()=="BUTTON"))
 7         {
 8             target=e.target;
 9         }//样式按钮
10         else if($(e.target).hasClass('btn')) {
11             target=e.target;
12             if(e.target.parentElement.tagName=='A')
13             {
14                 //<a><span class="btn">按钮<span></a>
15                 target=e.target.parentElement;
16             }
17         }
18 
19         if(target!=undefined)
20         {
21             ///事件执行先后顺序,如果直接在mouseup里面置灰,会屏蔽掉原有的点onclick击事件
22             // mousedown>mouseup>onclick>click>on()
23             $(target).click(function(){
24                 //a标签disabled属性无效
25                 if(target.tagName=='A')
26                 {
27                     $(target).addClass('a-disabled');
28                     setTimeout(function(){
29                         $(target).removeClass('a-disabled');
30                     },2000);
31                 }
32                 else{
33                     target.setAttribute('disabled','disabled');
34                     setTimeout(function(){
35                         target.removeAttribute('disabled');
36                     },2000);
37                 }
38 
39             });
40         }
41     };
42 </script>
1 <style>
2     .a-disabled
3     {
4         opacity: 0.6;
5         cursor: default;
6         pointer-events: none;
7     }
8 </style>

 

转载于:https://www.cnblogs.com/lyd2016/p/7026569.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值