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

语法

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+ */

/* 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;

});

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值