首页 > Web开发 > 详细

通过CSS规则禁止选中文字的实现代码

时间:2016-02-01 11:47:14      阅读:171      评论:0      收藏:0      [点我收藏+]

语法

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;
});

通过CSS规则禁止选中文字的实现代码

原文:http://www.jb51.net/css/178295.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!