无法调用方法tinymce

el_*_*_le 3 javascript tinymce

为什么会这样'cannot call method getContent of undefined',这怎么可能?它用tinyMCE设置我的textarea但不能做getContent.

tinyMCE.init({
            plugins: 'paste',
            theme : "advanced",
            mode : "specific_textareas",
            editor_selector : element,
            width : width,
            theme_advanced_buttons1 : "bold,italic,underline,strikethrough,bullist,numlist,undo,redo,",
            theme_advanced_buttons2 : "",
            theme_advanced_buttons3 : "",
            theme_advanced_toolbar_location : "top",
            theme_advanced_toolbar_align : "left",
            content_css : "hhhng.css",
            paste_text_sticky : true,
            //select pasteAsPlainText on startup
            setup : function(ed) {
                    ed.onInit.add(function(ed) {
                    ed.pasteAsPlainText = true;
                });
            }
});
var x = tinyMCE.get(element).getContent();
Run Code Online (Sandbox Code Playgroud)

更新

当我从按钮点击调用时工作,但为什么在初始化后不能立即工作?是的,它在文档就绪块中.这对我没有意义:S

$("#button").click( function(e) {

    e.preventDefault();
    console.log(tinyMCE.activeEditor.getContent());

});
Run Code Online (Sandbox Code Playgroud)

aln*_*h29 6

即使它在文档就绪块中,也可能是在调用init时TinyMCE不会立即创建自己.如果您希望在初始化后运行代码,那么您应该看看它是否提供了传递回调函数的方法.然后它会在它准备就绪后调用此函数.

事实上,你似乎已经在使用这样一个代码的函数:

//select pasteAsPlainText on startup
setup : function(ed) {
        ed.onInit.add(function(ed) {
        ed.pasteAsPlainText = true;
    });
}
Run Code Online (Sandbox Code Playgroud)

只需将您的post init代码添加到该函数体.