jquery和javascript屏蔽右键菜单及阻止事件冒泡

jquery屏蔽右键菜单

        $(document).ready(function(){
            $(document).bind("contextmenu",function(e){
                return false;
            });
        });


javascript屏蔽右键菜单 

 if (window.Event) 
        document.captureEvents(Event.MOUSEUP); 
        function nocontextmenu(){ 
         event.cancelBubble = true 
         event.returnValue = false; 
         return false; 
        } 
        function norightclick(e){ 
         if (window.Event){ 
          if (e.which == 2 || e.which == 3) 
          return false; 
         } 
         else 
          if (event.button == 2 || event.button == 3){ 
           event.cancelBubble = true 
           event.returnValue = false; 
           return false; 
          } 
        } 
        document.oncontextmenu = nocontextmenu; // for IE5+ 
        document.onmousedown = norightclick; // for all others 


jQuery阻止事件冒泡,但不阻止默认行为

event.stopPropagation(); 


jQuery阻止默认行为,不阻止事件冒泡

event.preventDefault();


jQuery阻止了默认事件,也阻止了默认行为

return false;


javascript阻止浏览器的默认行为

function stopDefault(e) {  
        //如果提供了事件对象,则这是一个非IE浏览器   
        if(e && e.preventDefault) {  
          //阻止默认浏览器动作(W3C)  
          e.preventDefault();  
        } else {  
          //IE中阻止函数器默认动作的方式   
          window.event.returnValue = false;   
        }  
        return false;  
    } 


javascript停止事件冒泡

function stopBubble(e) {  
    //如果提供了事件对象,则这是一个非IE浏览器  
    if(e && e.stopPropagation) {  
    //因此它支持W3C的stopPropagation()方法  
    e.stopPropagation();   
    } else {  
    //否则,我们需要使用IE的方式来取消事件冒泡   
    window.event.cancelBubble = true;  
    }  
    return false;   
} 






  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值