【发布时间】:2018-06-21 21:32:40
【问题描述】:
我正在使用 TinyMCE v4.7.9
使用模板时 (https://www.tinymce.com/docs/plugins/template/)
我想在内容编辑器中最后插入模板,而不是我所在的位置,是否有一些技巧可以做到这一点?我可以在对话框上添加一个“插入之后”按钮吗?
现在我被其他一些 P 标签困住了,我的模板是 DIV。
问候
【问题讨论】:
我正在使用 TinyMCE v4.7.9
使用模板时 (https://www.tinymce.com/docs/plugins/template/)
我想在内容编辑器中最后插入模板,而不是我所在的位置,是否有一些技巧可以做到这一点?我可以在对话框上添加一个“插入之后”按钮吗?
现在我被其他一些 P 标签困住了,我的模板是 DIV。
问候
【问题讨论】:
经过反复试验,没有办法找到答案,我找到了解决方法。
我用
在事件“BeforeSetContent”的设置中:
editor.on('BeforeSetContent', function (e) {
if (e.content.indexOf("<div data-insertafter") === 0) { //okej, insert after
editor.setContent(editor.getContent() + '<div class="row"></div>');//add an element to in the end
editor.selection.select(editor.getBody(), true);//select al
editor.selection.collapse(false);//set focus on that last div by inverting selection
e.content = e.content.replace("data-insertafter", "");//remove
}
});
【讨论】:
您当然可以修改模板插件来做到这一点...每个插件都附带一个缩小版和非缩小版,因此您只需修改非缩小版即可满足此需求。
【讨论】: