Jquery禁止鼠标右键菜单

$(document).ready(function(){
    $(document).bind("contextmenu",function(e){
        return false;
    });
});
// 禁用了右键以后点击右键什么都么有了,用户体验总会觉得缺点什么,那么就在右键里面自定义一些小效果。
$(document).bind("contextmenu",function(e){
	//在这里书写代码,构建个性右键化菜单
	return false;
});

// 还可以让用户不能选中页面中的文字,下面这段代码可以搞定
$('body').bind("selectstart",function(){
	return false;
});

注:bind事件处理功能为:为每一个匹配元素的特定事件(像click)绑定一个事件处理器函数。
参考:https://blog.csdn.net/iteye_13416/article/details/82364570

// 切换是否可以右键

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>屏蔽鼠标右键菜单</title>
</head>
<script type="text/javascript" src="jquery.min.js"></script>
<script>
    $(function(){
        //contextmenu事件返回false则屏蔽鼠标右键菜单
        $(document).bind("contextmenu",function(e){
                if($("#enabledRadio").prop("checked")){
                    return true;    
                }
                if($("#disabledRadio").prop("checked")){
                    return false;    
                }
            });
    })
</script>
<body>
    <div>
        <h3>JQuery屏蔽鼠标右键菜单</h3>
        <input type="radio" name="control" id="enabledRadio" checked="checked" />允许右键
        <input type="radio" name="control" id="disabledRadio" />禁止右键
    </div>
</body>
</html>

查看效果图
1)允许右键
在这里插入图片描述
2)禁止右键
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值