我尝试获取tinymce的内容,如下所示:

 var hallo = tinyMCE.activeEditor.getContent();
            alert(hallo);

但每次我收到此消息时:
Uncaught TypeError: Cannot read property 'getContent' of null

我正在使用tinymce 4。

谢谢

最佳答案

Cannot read property 'getContent' of null通常意味着TinyMCE无法找到您的文本框,这意味着对textarea的class的引用存在问题。

<form method="post" action="somepage">
    <textarea id="myTextArea" class="mceEditor">I should buy a boat. </textarea>
</form>

<button onclick="content()">Get content</button>

记下mceEditor类,我们现在将通知TinyMCE编辑器有关:
<script type="text/javascript">

    tinyMCE.init({
        mode : "specific_textareas",
        editor_selector : "mceEditor"   //<<<----
    });

</script>

现在,只需单击按钮即可获取该文本框的内容。
function content() {
    alert(tinyMCE.get('myTextArea').getContent());
}

这是工作中的 DEMO

07-25 23:08
查看更多