AI

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

开开2021-09-10 11:19:56128

各浏览器禁止选中文字各自有个的方法。

代码

复制代码
<!DOCTYPE html>

<html>
<body>

<div unselectable="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"
,保证各个浏览器都能禁止选中文字。

原文: https://blog.csdn.net/qq_31029729/article/details/49760007

广告