使用user-select禁止网页抉择文字
使用user-select禁止网页选择文字
http://www.wufangbo.com/css-jin-zhi-xuan-ze/
user-select有两个值:
none:用户不能选择文本
text:用户可以选择文本
注意:user-select不是一个W3C的CSS标准属性,浏览器支持的不完整,需要对每种浏览器进行调整。
IE6-9还没发现相关的CSS属性,禁止网页选择文字但是文本框中的文字可以选中,使用js实现:
http://www.wufangbo.com/css-jin-zhi-xuan-ze/
user-select有两个值:
none:用户不能选择文本
text:用户可以选择文本
注意:user-select不是一个W3C的CSS标准属性,浏览器支持的不完整,需要对每种浏览器进行调整。
body{ -moz-user-select: none; /*火狐*/ -webkit-user-select: none; /*webkit浏览器*/ -ms-user-select: none; /*IE10*/ -khtml-user-select: none; /*早期浏览器*/ user-select: none; }
IE6-9还没发现相关的CSS属性,禁止网页选择文字但是文本框中的文字可以选中,使用js实现:
//IE6-9 if (typeof(document.onselectstart) != "undefined") { // IE下禁止元素被选取 document.onselectstart = function (event){ if(event.target.tagName!="INPUT"){ return false; } } } else { // 高级浏览器下禁止元素被选取的变通办法 document.onmousedown = function (event){ if(event.target.tagName!="INPUT"){ return false; } } document.onmouseup = function(event){ if(event.target.tagName!="INPUT"){ return false; } } }