js-onSelectStart解释

IE&&Chrome中适用此方法

<script>  
document.onselectstart=function(){return false;}  
</script>  

onselectstart是防止内容被选中默认状态是true

<body onselectstart=return(event.srcElement.type=='text')>  
选不中  
<input type="text" name="" value="来选吧">  
</body>  

一般如果把它设置在整个body上时如果body里边有输入框需要选中文字时可以这样

function doIt(){  
    var now=event.srcElement;  
    if(now.tagName=="input"){  
        return true;  
    }  
    else{  
        return false;  
    }  
}

把他设定成函数

FF中对onselectstart方法是不支持的

在火狐中要使用css来控制

-moz-user-select:none;禁止选中文本

Chrome中的css解决方法

-khtml-user-select;禁止选中文本;也可使用js的方法来禁止

金牌狙击手

52html5是一个web前端|html5资源平台,为广大html5开发者及爱好者提供html5相关的教程、资讯、html5游戏、html5教程等,并涉及css3、javascript前端知识。