码迷,mamicode.com
首页 > Web开发 > 详细

js 鼠标放上选中

时间:2019-08-15 21:10:02      阅读:86      评论:0      收藏:0      [点我收藏+]

标签:html   ext   tps   cti   min   range   read   https   doctype   

<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<script src="https://code.jquery.com/jquery-3.4.1.min.js" type="text/javascript" charset="utf-8"></script>
<body>
    <div class=‘xz‘>
        ssssssssssssssssssssssssss
        ssssssssssssssssssssssssss
        <div>
            dddddddddddddddd
        </div>
    </div>
</body>
<script>
    $(document).ready(function(){
    $(".xz").hover(function(){
        this.focus();
        if(window.getSelection){
            var range=document.createRange();
            range.selectNodeContents(this);
            var selection = window.getSelection();
            selection.removeAllRanges();
            selection.addRange(range)            
            }
        else if(document.selection){
            //for ie
            var range=document.body.createTextRange()
            range.moveToElementText(this)
            range.select();
        }
    },function(){
        if(window.getSelection){
            var range=document.createRange();
            range.selectNodeContents(this);
            var selection = window.getSelection();
            selection.removeAllRanges();
        } else if(document.selection){
            //for ie
            var range=document.body.createTextRange()
            range.moveToElementText(none)
        }
    });
});
</script>
</html>

 

js 鼠标放上选中

标签:html   ext   tps   cti   min   range   read   https   doctype   

原文地址:https://www.cnblogs.com/chengfengchi/p/11360394.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!