简体   繁体   English

TinyMCE getContent 返回 Null

[英]TinyMCE getContent Returns Null

I'm trying to get the raw HTML out of TinyMCE editor.我正在尝试从 TinyMCE 编辑器中获取原始 HTML。 Here is the code I am using这是我正在使用的代码

      tinymce.init({
          selector: 'textarea',
          plugins: 'a11ychecker advcode casechange export formatpainter image editimage linkchecker autolink lists checklist media mediaembed pageembed permanentpen powerpaste table advtable tableofcontents tinycomments tinymcespellchecker',
          toolbar: 'a11ycheck addcomment showcomments casechange checklist code export formatpainter image editimage pageembed permanentpen table tableofcontents',
          toolbar_mode: 'floating',
          tinycomments_mode: 'embedded',
          tinycomments_author: 'Author name',

         
        });

        console.log (tinymce.get('content-text'))


In the console it says null.在控制台中它显示为空。 I have also used the active editor function.我还使用了活动编辑器功能。

console.log (tinymce.activeEditor.getContent())

Doing this gives me an error这样做会给我一个错误

Uncaught TypeError: Cannot read properties of null (reading 'getContent')
    at contact-us.html:62:43

I'm using TinyMCE version 6.1我正在使用 TinyMCE 6.1 版

Place the <script> to below the <textarea> and try again.<script>放在<textarea>下方,然后重试。

Or try to add ID onto textarea tag like或者尝试将 ID 添加到textarea标签上,例如

<textarea id="tinyarea">
...
</textarea>

and change selector in the js to并将js中的选择器更改为

selector: 'textarea#tinyarea',

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM