js获取鼠标选中文字事件,js怎么获取鼠标选中文字,下面贴出代码,由于兼容IE和大众浏览器,如下所示:
<script language="javascript"> (function(w){ var doc = document; var div = doc.getElementsByTagName('div')[0]; //var location = window.location; //location.href = "http://www.baidu.com/"; console.log(div); //console.log(location); div.onmouseup = function(e){ var e =e ||window.event; console.log(selectText()); } function selectText(){ if(document.selection){ //ie return document.selection.createRange().text; } else{ //标准 return window.getSelection().toString(); } } })(window); </script> |