zoukankan      html  css  js  c++  java
  • Jquery如何禁止鼠标右键菜单

     jquery中使用contextmenu事件,如果返回true,则允许右键菜单;如果返回false,则禁止右键菜单

    导入文件

    <script type="text/javascript" src="jquery.min.js"></script>

    js方法

    <script>
        $(function(){
            //contextmenu事件返回false则屏蔽鼠标右键菜单
            $(document).bind("contextmenu",function(e){
                    if($("#enabledRadio").prop("checked")){
                        return true;    
                    }
                    if($("#disabledRadio").prop("checked")){
                        return false;    
                    }
                });
        })
    </script>

    html页面

      <div>
            <h3>JQuery屏蔽鼠标右键菜单</h3>
            <input type="radio" name="control" id="enabledRadio" checked="checked" />允许右键
            <input type="radio" name="control" id="disabledRadio" />禁止右键
        </div>

    整体demo

    <!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)禁止右键

  • 相关阅读:
    MySQLSource-Flume
    Flume
    Hive| ETL清洗& 查询练习
    Hive-04 压缩| 存储
    Hive-03 查询
    Hive-02 DDL| DML
    shell基本用法
    Hive-01 配置| 架构原理
    HDFS-HA高可用 | Yarn-HA
    react-路由和Ant design
  • 原文地址:https://www.cnblogs.com/xielong/p/9713012.html
Copyright © 2011-2022 走看看