Firefox/Opera不支持onselectstart事件

如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Firefox/Opera不支持onselectstart事件</title>
  </head
  <body>
    <div id="d1" style="width:200px;height:200px;background:gold;">Text Text</div>
    <script type="text/javascript">
     
        var div = document.getElementById('d1');
        div.onselectstart = function(){
            console.log(3);
        }
    </script>
  </body>
</html>

当用鼠标去选定div内的文本时,IE/Safari/Chrome 的控制台输出了3,Firefox/Opera则没有输出。


1 IE可以使用onselectstart事件来阻止用户选定元素内文本,如下

1
<div onselectstart="return false">accc</div>

2 Firefox中可以使用CSS "-moz-user-select:none"属性来禁止文本选定

3 webkit浏览器可以使用“-khtml-user-select”,当然也可以使用方式1


CSS3 定义了“user-select”属性,如下


可惜所有浏览器都未实现,如FF4/Safar5/Chrome11/Opera10/IE10。


相关:

https://developer.mozilla.org/en/CSS/-moz-user-select

http://msdn.microsoft.com/en-us/library/ms536969%28VS.85%29.aspx 

http://www.w3.org/TR/2000/WD-css3-userint-20000216#user-select 

posted on   snandy  阅读(5240)  评论(1编辑  收藏  举报

< 2011年6月 >
29 30 31 1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 1 2
3 4 5 6 7 8 9

统计

点击右上角即可分享
微信分享提示