語法
Formal syntax: none | text | all | element
復制代碼代碼如下:
(-prefix-)user-select: none;
(-prefix-)user-select: text;
(-prefix-)user-select: all;
(-prefix-)user-select: element;
示例
復制代碼代碼如下:
.row-of-icons {
-webkit-user-select: none; /* Chrome all / Safari all */
-moz-user-select: none; /* Firefox all */
-ms-user-select: none; /* IE 10+ */</p>< p> /* No support for these yet, use at own risk */
-o-user-select: none;
user-select: none;
}
IE兼容性
目前在IE 10以及IE 10以上版本的浏覽器可以使用-ms-user-select這個規則,但在更早版本的IE,我們只能通過Javascript實現禁止選中文本:
復制代碼代碼如下:
$(el).attr('unselectable','on')
.CSS({'-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'
}).bind('selectstart', function(){
return false;
});