当出现多次时,我很难选择文本并替换该选择。它总是恢复到第一次出现并替换它。
这是我正在使用的脚本,如果选择只在我完美时出现。当它出现不止一次时,它会抓住第一个。
var self=$('#textarea');
GetSelected={};
GetSelected=function(){
var txt='';
if(window.getSelection){
txt=window.getSelection();
}
else if(document.getSelection){
txt=document.getSelection();
}
else if(document.selection){
txt=document.selection.createRange().text;
}
return txt;
}
self.html(self.html().replace(selection, '<b>' + selection + '</b>'));
有什么我遗漏的东西,知道要替换哪个选择吗?