尝试获取内容时出现timece错误

tinyMCE error whe trying to get content

本文关键字:timece 错误 获取      更新时间:2023-09-26

我得到这个错误:Uncaught TypeError: Cannot read property 'getContent' of undefined

if (tinymce.editors.length > 0) {
                alert('editor exist')
                var myEditor = tinyMCE.get['rteCaseHeading'].getContent();
                $("#bookId").html(myEditor);
            }

在Html中:

<textarea class="mceEditor" id="rteCaseHeading"  rows="10" cols="100" style="height: 300px"> </textarea>

我还在tinyMCE init期间指定了:editor_selector : "mceEditor",

我已经参考了关于这个错误的各种链接/问题并实现了

尽管编辑器的长度大于0,但仍会抛出错误。

有人,请建议我在这个问题上挣扎了2-3个小时以上。(更新)

我引用了这个链接并添加了以下代码:http://jsfiddle.net/9euk9/49/

 ed.on('change', function () {
                    ed.save();
                });

仍然没有运气。非常感谢!

<textarea>包含在<form></form>标签中。

检查下面的代码,

<form method="post" action="action_page">
<textarea class="mceEditor" id="rteCaseHeading"  rows="10" cols="100" style="height: 300px">testtestet</textarea>
</form>
<button onclick="content()">Get content</button>
Javascript

tinyMCE.init({
        mode : "specific_textareas",
        editor_selector : "mceEditor"  
});
function content(){
    alert(tinyMCE.get('rteCaseHeading').getContent());
}

工作小提琴 - http://jsfiddle.net/kqa13zz4/52/

注意:在fiddle中,我把function content()函数写成window.content = function()...,因为fiddle只接受这样的函数声明。

希望这对你有帮助!

您没有正确调用get()方法。你有这个:

var myEditor = tinyMCE.get['rteCaseHeading'].getContent();

…应该是这样:

var myEditor = tinyMCE.get('rteCaseHeading').getContent();

你写东西的方式是你试图访问tinyMCE对象上的数组-但是get是一个方法而不是数组-它是tinyMCE对象上的方法,因此需要括号而不是方括号。

https://www.tinymce.com/docs/api/tinymce/root_tinymce/得到

(TinyMCE 3和4的方法调用相同)