跳坑 阻止浏览器双击默认事件-----双击选中

来源:互联网 发布:淘宝ka是什么意思 编辑:程序博客网 时间:2024/06/10 08:02

首先 使用 e.preventDefault() 不起作用;

在网上找到的办法:

css:
 
 
body {
    -moz-user-select: none; /*火狐*/
    -webkit-user-select: none; /*webkit浏览器*/
    -ms-user-select: none; /*IE10*/
    -khtml-user-select: none; /*早期浏览器*/
    user-select: none;
}
 
 
js:
 
document.ondragstart = document.onselectstart = function(){return false;};


js的原理是 阻止网页中的文字被选中 直接放在js 中就好了

在 火狐 谷歌 opera 新版浏览器上都能使用  可使用 css兼容低版本浏览器

ps 对input. textarea 无效


原创粉丝点击