TinyMCE - 编写在顶部插入内容的插件
我正在尝试为 TinyMCE 编写一个插件,其功能是将内容添加到内容的开头。我知道以下命令将在光标的当前位置插入内容。如何强制将其插入到内容的开头?
tinyMCEPopup.editor.execCommand('mceInsertRawHTML', false, "halo world");
tinyMCEPopup.editor.execCommand('mceInsertContent', false, "halo world");
I am trying to write a plugin for TinyMCE with a feature to add content to the beginning of the content. I know the following command which will insert content at the current location of the cursor. How do I force it to insert it at the beginning of the content?
tinyMCEPopup.editor.execCommand('mceInsertRawHTML', false, "halo world");
tinyMCEPopup.editor.execCommand('mceInsertContent', false, "halo world");
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为此,您需要将光标位置设置为编辑器内容的开头。
您可以使用函数 setCursorLocation:
For this you will need to set the cursor location to the beginning of the editor content.
you may use the function setCursorLocation:
setCursorLocation
会将光标移动到第一个 html 元素的第一个内容字符的位置。这意味着如果您当前的 html 内容如下所示:abcd
那么
setCursorLocation
会将光标在和
abcd
之间移动。在某些情况下这是不可接受的。因此另一个解决方案是:ed.setContent('yourText' + ed.getContent())
。The
setCursorLocation
will move the cursor to the position of the first html element's first content character. This means that if your current html content looks like:<div>abcd</div>
then the
setCursorLocation
will move the cursor between the<div>
and theabcd
. In some cases this is not acceptable. So another solution would be:ed.setContent('yourText' + ed.getContent())
.