禁止选中

1.兼容性好

{

   moz-user-select: -moz-none;

  -moz-user-select: none;

  -o-user-select:none;

  -khtml-user-select:none; /* you could also put this in a class */

  -webkit-user-select:none;/* and add the CSS class here instead */

  -ms-user-select:none;

  user-select:none;/**禁止选中文字*/

}

2.在IE/Safari/Chrome中我们可以使用onselectstart事件来阻止用户选定元素内文本。

在标签中直接添加:oncontextmenu="return false" onselectstart="return false",但测试后发现火狐不兼容。

JS实现:

if(document.all){

    document.onselectstart=function(){returnfalse;};//for ie

}else{

   document.onmousedown=function(){returnfalse;};

   document.onmouseup=function(){returntrue;};

}

document.onselectstart =newFunction('event.returnValue=false;');

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容