2012-07-17 24 views
1

我想在javascript中的selectbox的onchange事件的觸發器上添加一些內容來填充tinymce主體。我嘗試了一些東西,但它確實不適合我,請引導我向正確的方向發展。 這裏是我的代碼,在附加textarea的如何在JavaScript事件的觸發器上添加一些內容的tinymce?

$(function() { 
appendTinyMCE(); 
function appendTinyMCE(){ 
    tinyMCE.init({ 

     // General options 
     mode : "textareas", 
     theme : "advanced", 
     plugins : "preview", 
     // Theme options 
     theme_advanced_buttons1 : "forecolor,backcolor,|,justifyleft,justifycenter,justifyright,justifyfull,bullist,numlist,|,formatselect,fontselect,fontsizeselect,sub,sup,|,bold,italic,underline,strikethrough", 
     theme_advanced_buttons2 : "", 
     theme_advanced_toolbar_location : "top", 
     theme_advanced_toolbar_align : "left", 
     theme_advanced_statusbar_location : "bottom", 
     theme_advanced_resizing : true 

});} 

})TinyMCE的;

下面是HTML代碼

<td> 
     <textarea rows="15" name="MyTinymceContent" cols="90" >MyTestContent</textarea> 

現在我想填充新的內容TinyMCE的,在JavaScript的選擇框的變化。所以我寫一篇關於選擇框

function populateMyTinyMCE() { 
    document.form.MyTinymceContent.value ="MyNewContent"; 
} 

的變化 下面的代碼片段,但它並沒有放在TinyMCE的身體新的內容。我不確定我在這裏錯過了什麼?

+0

+1準確和詳盡的問題 – Thariama 2012-07-17 11:12:25

回答

1

您可以撥打下面的一些事件觸發的任何:

tinyMCE.get('your_editor').setContent("MyNewContent"); 
//OR 
tinyMCE.activeEditor.setContent('MyNewContent'); 

參見:Here for More

+0

嘿的Sudhir,tinyMCE.activeEditor.setContent( 'MyNewContent')爲我工作。出於好奇,如果我想使用tinyMCE.get('your_editor').setContent(「MyNewContent」),我應該放置什麼而不是'your_editor',因爲我沒有在tinymce中看到任何id屬性。 – 2012-07-17 11:48:02

+0

'your_editor'將是您的textarea的編號... – 2012-07-17 11:52:28

+0

如果您的textarea沒有id「內容」將被用作默認值 – Thariama 2012-07-17 12:25:34

0

嘗試

tinyMCE.activeEditor.setContent("MyNewContent"); 
2

TinyMCE的不等於textarea的。在編輯器初始化時,創建了一個可以自定義的iframe。此iframe保存編輯器內容,並不時寫回編輯器源html元素(在您的情況下爲textarea)。要設置編輯器內容,您需要使用tinymce setContent函數。我會告訴替代太:

function populateMyTinyMCE() { 

    var editor = tinymce.editors[0]; 

    // other ways to get the editor instance 
    // editor = tinymce.get('my editor id'); 
    // editor = tinymce.activeEditor; 

    editor.setContent('my new content'); 

    // alternate way of setting the content 
    // editor.getBody().innerHTML = 'my new content'; 
} 
相關問題