日期:2014-05-16  浏览次数:20419 次

在jquery 下错误提示document.selection.CreateRange().text;
function getValue(obj){
obj.select();
var sel=""
sel=document.selection.CreateRange().text;
sel.text = obj;

}

上面这段代码不支持document.selection.CreateRange().text,能否帮忙改一下,谢谢

------解决方案--------------------
document.selection  在IE中才有的。firefox/chrome/ 支持 obj.selectionStart,obj.selectionEnd 这两个属性
要取得选择的文本,下面这样试试
 if(document.selection){
    return document.selection.createRange().text;
 }else{
    return obj.value.substring(obj.selectionStart,obj.selectionEnd);
 }