开发者

How to replace certain text/string in selected area using javascript

I have written a text editor using JavaScript.

Here I am not storing the written text in any variable, Now I want to replace some text/string of some selected text with other text/string.

Can anyone suggest me, how to do it using JavaScript.

T开发者_如何学Pythonhanks


If im understanding you correctly the following script could help you:

var selectedText = document.selection;
if (selectedText.type == 'Text') {
    var newRange = selectedText.createRange();
    var replacedText = newRange.text.replace("replacingText", "textToreplace);
}

Then the variable replacedText is the replaced version of your selected text.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜