阻止元素被选中

1.IE10+实现方式,css3

.unselect {
    -webkit-user-select: none; 
    -moz-user-select: none;    
    -khtml-user-select: none;  
    -ms-user-select: none;    

    /* 以下两个属性目前并未支持,写在这里为了减少风险 */
    -o-user-select: none;
    user-select: none;  
}

user-select: auto; => 用户可以选中元素中的内容
user-select: none; => 用户不可选中元素中的内容
user-select: text; => 用户可以选中元素中的文字
目前 user-select 兼容 Chrome 6+、Firefox、IE 10+、Opera 15+、Safari 3.1+。

2.IE5.5-9的实现,unselectable

<span unselectable="on"></span>

unselectable属性不具有继承性,如果要设置整个页面,就要遍历所有子元素并为各子元素添加该属性才有效。

3.参考

《JavaScript框架设计》──9.3.2 user-select 

难道你以为仅仅这样就可以阻止firefox选中文本了嘛

原文地址:https://www.cnblogs.com/jiyang2008/p/5068695.html