javascript - 跨浏览器禁用用户选择(Ctrl + A)

标签 javascript jquery html css event-handling

默认情况下,用户可以拖动并选择屏幕元素/按 CTRL + A ,所有元素都会变成蓝色和模糊(选中)。但是,有什么办法可以阻止这个事件吗?谢谢

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

最佳答案

user-select:none;
-moz-user-select: none;
-webkit-user-select: none;
-ms-user-select: none;

将以下 user-select 属性添加到您不想变成蓝色的元素。将它添加到 body 会将 selectableeditable 元素变为不可 selectableeditable。因此,建议在特定元素上使用它,例如

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

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

Documentation

关于javascript - 跨浏览器禁用用户选择(Ctrl + A),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14598070/

相关文章:

javascript - angular.js 模块化 - 多个 ng-apps?

JavaScript 帮助程序库?没有 DOM 或 AJAX 的东西

jquery - 如何将 jquery select2 绑定(bind)到新添加的选择?

javascript - 搜索并查找以特定数字开头的数字

html - 使用 xpath 获取下一个元素

javascript - 我的动态表行创建代码不起作用

javascript - IONIC 构建产品

javascript - 如何防止无限递归

javascript - 将数组值从 html 传递到 javascript

javascript - 从所有数组项中切片字符