如何自动填充tinymce的内容?
how to auto populate the contents of a tinymce?
我正在尝试自动填充我的 tinymce 的内容,这将在某些情况下完成。我尝试进行一些控制台测试以查看 jquery 函数将在其上运行。
我试过了:
$("#tinymce").text("test");
$("#tinymce").html("test");
$("#tinymce").val("test");
但他们都返回了这个错误:
VM3476:1 Uncaught TypeError: $(...).val is not a function
at :1:15
<body id="tinymce" class="mceContentBody " onload="window.parent.tinyMCE.get('htmleditor1').onLoad.dispatch();" contenteditable="true" spellcheck="false" data-gramm_id="e2122774-06e2-55e3-4d20-705ac5c51517" data-gramm="true" data-gramm_editor="true">
<g class="gr_ gr_3 gr-alert gr_spell gr_run_anim ContextualSpelling ins-del multiReplace" id="3" data-gr-id="3">sadasd</g><br>
</body>
如果在 tinyMCE 初始化之后
您必须使用 setContent() 方法,以便设置完整内容
tinyMCE.activeEditor.setContent('My test!');
或者如果您只想更改选定的部分
tinyMCE.activeEditor.selection.setContent('<strong>Some contents</strong>');
如果在 tinyMCE 初始化之前
您可以直接设置您的 HTML 容器
$('textarea').text('My text!');
我正在尝试自动填充我的 tinymce 的内容,这将在某些情况下完成。我尝试进行一些控制台测试以查看 jquery 函数将在其上运行。
我试过了:
$("#tinymce").text("test");
$("#tinymce").html("test");
$("#tinymce").val("test");
但他们都返回了这个错误:
VM3476:1 Uncaught TypeError: $(...).val is not a function at :1:15
<body id="tinymce" class="mceContentBody " onload="window.parent.tinyMCE.get('htmleditor1').onLoad.dispatch();" contenteditable="true" spellcheck="false" data-gramm_id="e2122774-06e2-55e3-4d20-705ac5c51517" data-gramm="true" data-gramm_editor="true">
<g class="gr_ gr_3 gr-alert gr_spell gr_run_anim ContextualSpelling ins-del multiReplace" id="3" data-gr-id="3">sadasd</g><br>
</body>
如果在 tinyMCE 初始化之后
您必须使用 setContent() 方法,以便设置完整内容
tinyMCE.activeEditor.setContent('My test!');
或者如果您只想更改选定的部分
tinyMCE.activeEditor.selection.setContent('<strong>Some contents</strong>');
如果在 tinyMCE 初始化之前
您可以直接设置您的 HTML 容器
$('textarea').text('My text!');