Ste*_*han 1 javascript tinymce highlighting
我有以下短语:
The birds fly in the sky near planes.
0123456789012345678901234567890123456
1 2 3
Run Code Online (Sandbox Code Playgroud)
in the sky如果我知道短语的开头(14)和结束(23),我如何用TinyMce 突出显示?
我想使用该setRng方法,但我没有找到任何示例代码.
这是我提出的解决方案:
var ed = tinyMCE.activeEditor;
var range = ed.selection.getRng();
range.setStart(textNode, start);
range.setEnd(textNode, end);
ed.selection.setRng(range);
Run Code Online (Sandbox Code Playgroud)
地点:
getElementById或任何其他速记属性(parent,nextSibling等等)我更喜欢这个解决方案,因为我只使用tinyMCE API.我不依赖于可以从浏览器到浏览器改变(在行为中,在错误中......)的对象和方法.