如何在tinymce中找到节点的结尾?

How to find the end of node in tinymce?

我想在 tinymce 中的下一个结束标记结束后插入一个文本。对于前。 <p>This is <span>This is a s|pan</span>paragraph</p>。 '|'显示我的光标位置,我需要将光标放在 '</span>|'.

之后

以下是您需要执行的操作的大纲:

// get a reference to the Editor instance
// (depending on your scenario, this may come from a different place)
var editor = tinymce.activeEditor;

// get the node your cursor is in - the one you want to insert after
var endNode = editor.selection.getEnd();

// move the selection after the current node
editor.selection.select(endNode).collapse(false);

// insert your content
editor.selection.setContent("abc");

您可以使用 the API docs 使其真正起作用。我上面写的完全基于文档 - 因为我现在没有时间测试它 - 所以它可能不会即插即用。

正在将之前的答案和评论编译成一个代码块...

// Get a reference to the Editor instance
// (depending on your scenario, this may come from a different place)
var editor = tinymce.activeEditor;

// get the node your cursor is in - the one you want to insert after
var endNode = editor.selection.getEnd();

// move the selection after the current node
editor.selection.select(endNode);
editor.selection.collapse(false);

// insert your content
editor.selection.setContent("abc");