您的位置:首页 > 其它

各浏览器禁止选中文字方法

2015-11-10 15:34 246 查看
各浏览器禁止选中文字各自有个的方法。

代码

<!DOCTYPE html>
<html>
<body>
<divunselectable="on" style="background:#ccc;">unselectable="on"</div>
<br/>
<div style="background:#ccc;-webkit-user-select:none;">-webkit-user-select:none;</div>
<br/>
<div style="background:#ccc;-moz-user-select:none;">-moz-user-select:none;</div>
<br/>
<div style="background:#ccc;"onselectstart="return false;">onselectstart="return
false;"</div>
</body>
</html>

效果


Chrome Safari

Firefox

IE

Opera

unselectable="on"

  no  

  no  

  yes  

  yes  

-webkit-user-select:none;

  yes  

  no  

  no  

  no  

-moz-user-select:none;

  no  

  yes  

  no  

  no  

onselectstart="return false;"

  yes  

  no  

  yes  

  no  







总结

给标签设置样式-moz-user-select:none;-webkit-user-select:none;,同时标签设置unselectable="on",保证各个浏览器都能禁止选中文字。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: