js 如何禁止选中文本

js最佳方案

//直接上干货:
if(document.all){
    document.onselectstart= function(){return false;}; //for ie
}else{
    document.onmousedown= function(){return false;};
    document.onmouseup= function(){return true;};
}
document.onselectstart = new Function('event.returnValue=false;');
 
//劫持开始选择事件和(或)鼠标按下、抬起事件。

css最佳方案


你可能感兴趣的:(js 如何禁止选中文本)