我想在javascript中选择框的onchange事件触发时用一些内容填充tinymce主体。我尝试了一些东西,但确实如此 不适合我。请引导我正确的方向。 这是我的代码,将tinymce附加到textarea
$(function() {
appendTinyMCE();
function appendTinyMCE(){
tinyMCE.init({
// General options
mode : "textareas",
theme : "advanced",
plugins : "preview",
// Theme options
theme_advanced_buttons1 : "forecolor,backcolor,|,justifyleft,justifycenter,justifyright,justifyfull,bullist,numlist,|,formatselect,fontselect,fontsizeselect,sub,sup,|,bold,italic,underline,strikethrough",
theme_advanced_buttons2 : "",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_statusbar_location : "bottom",
theme_advanced_resizing : true
});}
});
这是html代码
<td>
<textarea rows="15" name="MyTinymceContent" cols="90" >MyTestContent</textarea>
现在我想在 javascript 中更改选择框时用新内容填充tinymce。所以我在更改时编写了以下代码片段 选择框的
function populateMyTinyMCE() {
document.form.MyTinymceContent.value ="MyNewContent";
}
但它不会将新内容放入tinymce主体中。我不确定我在这里缺少什么?
最佳答案
Tinymce 不等于文本区域。编辑器初始化时,会创建一个可编辑内容的 iframe。该 iframe 保存编辑器内容,并时不时地写回编辑器源 html 元素(在您的情况下为文本区域)。要设置编辑器内容,您需要使用tinymce setContent
函数。我也会展示替代方案:
function populateMyTinyMCE() {
var editor = tinymce.editors[0];
// other ways to get the editor instance
// editor = tinymce.get('my editor id');
// editor = tinymce.activeEditor;
editor.setContent('my new content');
// alternate way of setting the content
// editor.getBody().innerHTML = 'my new content';
}
关于javascript - 如何在 javascript 事件触发时用一些内容填充tinymce?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11521063/