网站禁止双击选中文字解决方案

3,851 阅读1分钟

当我们用 ondblclick 时可能不想用双击选中文本的效果,可以用已下下方法:

方法一

window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();

方法二:css方案

小缺点:直接禁止选中功能

-moz-user-select: none; /*火狐*/
-webkit-user-select: none; /*webkit浏览器*/
-ms-user-select: none; /*IE10*/
-khtml-user-select: none; /*早期浏览器*/
user-select: none;