用另一个文本替换选定的 [英] Replacing selected with another text
问题描述
我正在尝试用其他文本替换所选文本。
考虑以下是文本行。
I am trying to replace selected text with another text.
Consider following is the line of text.
Hello world.Good早上好。你好,世界。早上好。
Hello world.Good morning. Hello world. Good morning.
如果我选择第二个上午
文本,我想要更换早上的文字与夜晚。因此输出需要如下所示:
Here if I select second morning
text and I want replace morning text with night. So that output need to look like this:
Hello world.Good早上好。你好,世界。晚安。
Hello world.Good morning. Hello world. Good night.
我尝试更换功能,但它正在取代第一天早上的文字。
有人能建议解决方案吗为此?
I tried replace function, but it is replacing first morning text.
Can anyone suggest solution for this?
推荐答案
要获取HTML5中的当前选择,请使用 DOM Range API 。
To get the current selection in HTML5, use the DOM Range API.
要编辑选择,选择API 。
另请参阅:文本选择API在哪里?
如果你使用jQuery,那么使用 wrapSelection插件
If you use jQuery, then use the wrapSelection plugin
这篇关于用另一个文本替换选定的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!