默认情况下,用户可以拖动并选择屏幕元素/按 CTRL + A ,所有元素都会变成蓝色和模糊(选中)。但是,有什么办法可以阻止这个事件吗?谢谢
有没有什么简单的方法,比如在浏览器中添加一些限制,或者在body标签中添加一些属性,就可以解决这个问题?
最佳答案
user-select:none;
-moz-user-select: none;
-webkit-user-select: none;
-ms-user-select: none;
将以下 user-select
属性添加到您不想变成蓝色的元素。将它添加到 body 会将 selectable
或 editable
元素变为不可 selectable
或 editable
。因此,建议在特定元素上使用它,例如
div, image, iframe {
user-select:none;
-moz-user-select: none;
-webkit-user-select: none;
-ms-user-select: none;
}
或者您可以查看更多信息:
关于javascript - 跨浏览器禁用用户选择(Ctrl + A),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14598070/