在光标所在的TinyMCE编辑器中插入文本

问题描述:

我一直试图将文本插入TinyMCE编辑器中的焦点段落元素(< p> ),确切地说光标在哪里但没有运气!

I've been trying to insert text into the TinyMCE Editor at the focused paragraph element (<p>) exactly where the cursor is but got no luck!!

var elem = tinyMCE.activeEditor.dom.get('tinymce');
var child = elem.firstChild;
while (child) {
    if (child.focused) {
        $(child).insertAtCaret("some text");
    }
    child = child.nextSibling;
}

如果有人知道如何解决这个问题,我将非常感激。

If anyone has any idea on how to solve this I'll be very thankful.

您应该使用命令 mceInsertContent
请参阅 TinyMCE文档

tinymce.activeEditor.execCommand('mceInsertContent', false, "some text");