jquery - 如何动态设置tinymce内容

标签 jquery tinymce-4

我正在尝试动态更改 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/

相关文章:

jquery - 如何隐藏 Vimeo 控件

javascript - 如何在tinyMCE事件编辑器弹出窗口中的自定义按钮上应用CSS

javascript - 如何向 TinyMCE4 添加自定义帮助菜单?

javascript - 通过 HTML 设置 TinyMCE 文本区域的内容

twitter-bootstrap - Bootstrap 模式中的tinymce : wrong dropdown position on scroll

javascript - 使用 Jquery 在文本框上启用 Click 事件

jQuery UI 自动完成小部件 : modifying response data in "response" event doesn't have any effect

css - 在 IE 中更改 TinyMCE 表的边框颜色

javascript - 如何在 jQuery 中停止 onChange 事件

javascript - 手动显示和隐藏 jQuery ui 工具提示