テキストを選択して、複数回出現する場合にその選択を置き換えるのに苦労しています。常に最初に出現したものに戻り、それを置き換えます。
これが私が使用しているスクリプトであり、選択が一度だけ表示される場合、私は完全です。複数回出現する場合は、最初のものを取得します。
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>'));
どの選択を置き換えるかを知っている、私が見逃しているものはありますか?