我正在尝试动态更改 tinymce 编辑器的内容。 即使这个步骤也不起作用。实际上我想把内容放在 ajax 成功上,但是因为它不工作我不能继续。
我收到类型错误 tinemce.get() is null and tinymce.activeEditor is null erros
<textarea style="height:700px" name="proposal" id="proposal" >
hi
</textarea>
<script>
$(document).ready(function () {
tinymce.init({
selector: "#proposal",
height: 250,
theme: "modern",
plugins: [
"autoresize advlist autolink lists link image charmap print preview hr anchor pagebreak",
"searchreplace wordcount visualblocks visualchars code fullscreen",
"insertdatetime media nonbreaking save table contextmenu directionality",
"emoticons template paste textcolor colorpicker textpattern imagetools codesample toc"
],
toolbar1: "undo redo | insert | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image | print preview media | forecolor backcolor emoticons | codesample",
image_advtab: true,
content_css: [
"https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css",
],
});
var content = "<p>Hello World </p>";
tinyMCE.get("proposal").setContent(content);//not working
tinyMCE.activeEditor.setContent(content);//not working
});
<script>
最佳答案
在 Tinymce 4 中你可以试试:
// Sets the HTML contents of the activeEditor editor
tinymce.activeEditor.setContent('<span>some</span> html');
// Sets the raw contents of the activeEditor editor
tinymce.activeEditor.setContent('<span>some</span> html', {format: 'raw'});
// Sets the content of a specific editor (my_editor in this example)
tinymce.get('my_editor').setContent(data);
// Sets the bbcode contents of the activeEditor editor if the bbcode plugin was added
tinymce.activeEditor.setContent('[b]some[/b] html', {format: 'bbcode'});
通过 Tinymce 阅读更多内容
关于jquery - 如何动态设置tinymce内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44299660/