您的位置:首页 > Web前端 > JavaScript

用javascript获取选中的文字

2012-01-04 20:44 405 查看
function getSelectText() {

return document.selection && document.selection.createRange().text || window.getSelection && window.getSelection() || document.getSelection && document.getSelection() || '';

}

function getSelectText()
{
var txt = null;
if (window.getSelection){ // mozilla FF
txt = window.getSelection();
}else if (document.getSelection){
txt = document.getSelection();
}else if (document.selection){ //IE
txt = document.selection.createRange().text;
}
return txt;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: