TinyMCE错误的焦点位置

时间:2017-04-03 09:41:09

标签: javascript tinymce focus editor

我正在努力关注编辑器内容。它将焦点位置放在内容的开头,但它应该在内容之后。你能建议我如何将焦点位置移动到文本末尾吗?

<html>
<body>
    <textarea id="mytextarea">
      The focus will appear before this text. Should be after.
    </textarea>
<script>
    tinymce.init({ 
        selector: '#mytextarea',
        menubar: false,
    });

    setTimeout(function() {
        tinymce.execCommand('mceFocus');
    }, 2000)
</script>
</body>
</html>

以下是工作示例https://jsfiddle.net/iosipov83/o10ut0g1/

1 个答案:

答案 0 :(得分:0)

在您的TinyMCE初始化中,您可以添加以下内容:

setup: function (editor) {
    editor.on('init', function () {
        editor.focus();
        editor.selection.select(editor.getBody(), true);
        editor.selection.collapse(false);
    });
}

这应该将光标移动到内容的最末端。

(注意:请不要双重发布您的问题......当有人要求澄清时更新您的原始帖子会更好)