标签:content focus cti 选中文字 element rip span tps toe
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <div id="a">aaa</div> <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.js"></script> <script type="text/javascript"> $("#a").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> </body> </html>
标签:content focus cti 选中文字 element rip span tps toe
原文地址:http://www.cnblogs.com/dhsz/p/6872943.html