Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/476.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何阻止选中文本?_Javascript_Jquery_Cross Browser_Textselection - Fatal编程技术网

Javascript 如何阻止选中文本?

Javascript 如何阻止选中文本?,javascript,jquery,cross-browser,textselection,Javascript,Jquery,Cross Browser,Textselection,在我的web应用程序中,用户有时可以多次单击同一按钮,跳过消息和内容,从而选中 那么,我如何使用Javascript(jQuery)来防止这种情况呢?这个解决方案对我来说很有效: 您不需要脚本,以下是css: -webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: no

在我的web应用程序中,用户有时可以多次单击同一按钮,跳过消息和内容,从而选中


那么,我如何使用Javascript(jQuery)来防止这种情况呢?

这个解决方案对我来说很有效:


您不需要脚本,以下是css:

-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;

它会阻止他们继续浏览信息吗?如果不是的话,我建议不要这样做,因为这可能也会阻止他们选择文本。我觉得这不会影响他们的导航能力——只是意外地选择了。马雷克在下面的答案中包含的链接只允许在某些元素上禁用文本选择。Ben大概只会禁用一个杀死用户的标记的选择。该url似乎已移动到:链接中的示例不适用于最新版本的Jquery。$。浏览器已经不存在了。对于那些遇到这个答案的人来说,Blowsie描述的CSS方法是一个更好的解决方案(并且与链接的jQuery答案做相同的事情)。询问的人可能预先决定要使用JS来实现这一点,但你的答案比任何脚本都好+1在Chrome 25中工作,但在IE10中不适用于我。Ctrl+A选择页面上的所有文本。如果我双击文本,它会阻止文本被选中,但如果我从未使用此CSS的区域拖动到使用此CSS的区域,它仍会高亮显示文本。
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;