2011-11-24 142 views
4

我收到此消息:tinyMCE.get("message_data_" + msg_id) is undefined在Firebug後 我點擊按鈕提交表單。tinyMCE.get(「content」)未定義

msg_id定義,我檢查了它。 message_data_也被定義。 函數tinyMCE.get不是由於某種原因。

回答

3

如果您使用的是單個編輯器實例,則可以使用tinymce.editors[0]而不是tinyMCE.get("message_data_" + msg_id)

+1

是它應該是'tinyMCE'?而我仍然無法修復我的。 – Blaise

+1

小腸中的錫酸鹽是正確的方法。你也可以使用tinymce.activeEditor – Thariama

+4

對於有這個問題的人來說,找出什麼可用的tinymce方法(以及每個方法的正確套路)的另一種方法是使用firebug來打破你想要調用的get方法,並探索可用的函數tinyMCE類型。幫了我很多。 –

0

,如果您使用的是一個形式的多個編輯器,那麼你可以創建一個函數,並得到其數值 即

// Declare a function to get editor value 
function tinyMca_text(field_id) { 

if (jQuery("#"+field_id+":hidden").length > 0) 
{ 
return tinyMCE.get(field_id).getContent(); 
} 
else 
{ 
    return jQuery('#'+field_id).val(); 
} 

} 

// show that value 

console.log(tinyMca_text('field')); 
1

如果你沒有過的TinyMCE的init方法控制的話,你可以按照這個解決方案。如果TinyMCE未初始化,基本上它會增加一個回退。

jQuery(document).ready(function($) { 

    function myCustomSetContent(id, content) { 
     // Check if TinyMCE is defined or not. 
     if(typeof tinymce != "undefined") { 
      var editor = tinymce.get(id); 
      // Check if TinyMCE is initialized properly or not. 
      if(editor && editor instanceof tinymce.Editor) { 
       editor.setContent(text); 
       editor.save({ no_events: true }); 
      } else { 
       // Fallback 
       // If TinyMCE is not initialized then directly set the value in textarea. 
       //TinyMCE will take up this value when it gets initialized. 
       jQuery('#'+id).val(text); 
      } 
      return true; 
     } 
     return false; 
    } 

    function myCustomGetContent(id) { 
     // Check if TinyMCE is defined or not. 
     if(typeof tinymce != "undefined") { 
      var editor = tinymce.get(id); 
      // Check if TinyMCE is initialized properly or not. 
      if(editor && editor instanceof tinymce.Editor) { 
       return editor.getContent(); 
      } else { 
       // Fallback 
       // If TinyMCE is not initialized then directly set the value in textarea. 
       // TinyMCE will take up this value when it gets initialized. 
       return jQuery('#'+id).val(); 
      } 
     } 
     return ''; 
    } 

    $(".class-to-update-content").on("click", function(e) { 
     myCustomSetContent("tinymce-editor-id", "New Content in Editor"); 
    }); 

    $(".class-to-get-content").on("click", function(e) { 
     $("div.class-to-display-content").html(myCustomGetContent("tinymce-editor-id")); 
    }); 
}); 

編號:http://blog.incognitech.in/tinymce-undefined-issue/