在tinyMCE富文本编辑器中在光标位置插入文本

insert text at cursor position in tinyMCE rich text editor

本文关键字:光标 位置 插入文本 文本编辑 tinyMCE 文本 编辑器      更新时间:2023-09-26

我有几个下拉框,应该在tinyMCE富文本编辑器的光标位置插入动态文本(根据选择)。

我发现了很多与上述问题相关的帖子,如下所示,它目前与我的代码不工作,也没有在控制台给出任何错误。

tinyMCE.execInstanceCommand('text',"mceInsertContent",false,"This is the text to be inserted");
// here 'text' is id of textarea on which TinyMCE is rendered

我猜当我点击下拉框时,我在文本编辑器中失去了焦点,但我仍然无法解决这个问题。

需要使用execCommand代替下面的execInstanceCommand

tinyMCE.execCommand('mceInsertContent',false,"This is the text to be inserted");

原因是我使用的是tinyMCE旧版本(2X),所以大多数命令不能使用旧的API。