天天看点

html防止文本被选中

如何防止浏览器中文本被选中呢?

ie中,使文本所在控件的onselectstart 事件返回false

html防止文本被选中

<script  type="text/javascript" charset="utf-8">  

window.onload=function()  

{  

    var movespan222=$('#movespan');  

    //alert(movespan222);  

    drag(movespan222);  

    if(isietest){//当浏览器是ie时  

        com.whuang.hsj.$$id('movespan').onselectstart=function()//禁止文本被选中  

        {  

            return false;  

        }  

    }  

}  

 </script>  

火狐和chrome中,使用css

html防止文本被选中

.cannot_select{  

    -moz-user-select:none;/*火狐*/  

    -webkit-user-select:none;/*webkit浏览器*/  

    -ms-user-select:none;/*ie10*/  

    -khtml-user-select:none;/*早期浏览器*/  

    user-select:none;  

 参考:http://www.baidu.com/link?url=twlih_4xickfqwh7g4yrn_bscjzgeh8gqy2349euhmf2lwvc3uso3_fnp6lvmpbo3l-r5wh8t8_pz3pjpehd6q

继续阅读