首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

在jquery 下异常提示document.selection.CreateRange().text

2013-09-05 
在jquery 下错误提示document.selection.CreateRange().textfunction getValue(obj){obj.select()var se

在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);
 }

热点排行