如何在TinyMCE中突出显示给定的文本? [英] How to highlight a given text in TinyMCE?

查看:110
本文介绍了如何在TinyMCE中突出显示给定的文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下短语:

The birds fly in the sky near planes.
0123456789012345678901234567890123456
          1         2         3 

如何突出显示和TinyMce一起?

How can I highlight in the sky with TinyMce if I know the start(14) and end(23) of the phrase ?

我想用 setRng 方法,但我没有找到任何示例代码。

I would like to use the setRng method but I didn't find any sample code.

推荐答案

以下是我提出的解决方案:

Here is the solution I came up with :

var ed = tinyMCE.activeEditor;
var range = ed.selection.getRng();
range.setStart(textNode, start);
range.setEnd(textNode, end);
ed.selection.setRng(range); 

其中:


  • textNode 可以是DOM文本节点,您可以使用 getElementById 或任何其他简写属性()进行检索父母 nextSibling 等)

  • 开始结束分别是您要选择的文本的开头和结尾

  • textNode can be a DOM text node that you can retrieve with getElementById or any other short-hand properties (parent, nextSibling etc)
  • start and end are respectively the beginning and the end of the text you want to select

我更喜欢这个解决方案,因为我只使用 tinyMCE API。我不依赖于可以从浏览器到浏览器更改(在行为中,在错误中......)的对象和方法。

I prefer this solution because I only use the tinyMCE API. I don't rely on objects and methods that can change (in behavior, in bugs ...) from browser to browser.

这篇关于如何在TinyMCE中突出显示给定的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆