【问题标题】:Cross browser disable the user select (Ctrl + A)跨浏览器禁用用户选择(Ctrl + A)
【发布时间】:2013-01-13 22:02:45
【问题描述】:

默认情况下,用户可以拖动并选择屏幕项目/按 CTRL + A ,所有项目将变为蓝色并模糊(选中)。但是,有没有办法阻止这个事件?谢谢

有没有什么简单的方法,比如在浏览器中添加一些限制或者在body标签中添加一些属性可以解决问题?

【问题讨论】:

标签: javascript jquery html css event-handling


【解决方案1】:
user-select:none;
-moz-user-select: none;
-webkit-user-select: none;
-ms-user-select: none;

将 Follow user-select 属性添加到您不想变成蓝色的元素。将其添加到正文将把selectableeditable 元素变为不是selectableeditable。因此,建议在特定元素上使用它,例如

div, image, iframe {
    user-select:none;
    -moz-user-select: none;
    -webkit-user-select: none;
    -ms-user-select: none;
}

或者您可以查看更多信息:

Documentation

【讨论】:

    【解决方案2】:

    你可以使用 jquery 来做到这一点

    $(function(){   
    $(document).keydown(function(objEvent) {        
        if (objEvent.ctrlKey) {          
            if (objEvent.keyCode == 65) {                         
                objEvent.disableTextSelect();
                return false;
            }            
        }        
    });
    });    
    

    希望它有效,此代码禁用浏览器上的 ctrl+a

    【讨论】:

      猜你喜欢
      • 2011-01-25
      • 1970-01-01
      • 1970-01-01
      • 2016-10-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-22
      相关资源
      最近更新 更多