js 获取鼠标选中值

if (window.getSelection) {//一般浏览器
userSelection = window.getSelection();
} else if (document.selection) {
//IE浏览器、Opera
userSelection = document.selection.createRange();
}
var strInput="";
try{
strInput+=" "+userSelection.toString();
}catch(e){//I兼容IE

strInput+=" "+userSelection.text;
}
谷歌中对象

 IE中对象

 


posted @ 2016-08-10 12:22  __sarah  Views(1905)  Comments(0Edit  收藏  举报