2011-10-13 41 views
0

好的,我有一個div,當你點擊div時,我插入一個textarea,然後將tinyMCE controll添加到該textarea。好的,然後你輸入wsgi編輯器並按保存來保存它。TinyMCE Interst現有的HTML

然後html格式的tinyMCE編輯器被保存,並且textarea和tinyMCE元素被刪除,並且tinyMCE中的html被再次插入到div中。

這很好,現在,當我點擊div時,使用HTML,我希望該HTML顯示在tunyMCE編輯器內部。

這就是我所做的,但是一旦我點擊div,它會添加html,然後刪除它,爲什麼會發生這種情況?

 // Click on the div element 
    $(".editable").live("click", function(e){ 

     var f = $(this); 
     // get the html if it is there 
     html = f.html(); 
     // insert a textarea with a unique id 
     f.html('<textarea class="item_html" id="'+ e.timeStamp +'"></textarea> ') 
     f.css("height","100%") 
     //add tinyMCE control to the textarea 
     tinyMCE.execCommand(
      'mceAddControl', 
      false, 
      f.find("textarea").attr("id") 
     ); 
     // if there was html insode the div clicked on, add it into the editor 
     tinyMCE.execCommand(
      'mceInsertContent', 
      false, 
      html 
     ); 
    }); 
+0

你能爲此創建一個小提琴嗎? (http://jsfiddle.net) – Thariama

+0

這裏你去http://jsfiddle.net/M3gNm/3/ – Harry

+0

點擊div元素 – Harry

回答

1

的部分

// If there is html in the div clicked, add it to the mce editor 
if (html) { 
    tinyMCE.activeEditor.setContent('html'); 
} 

將無法​​正常工作,並拋出一個錯誤,因爲編輯器實例沒有完全在那個時候初始化。

看看我所做的更改。這裏:http://jsfiddle.net/M3gNm/9/ 編輯內容

+0

但它仍然刪除內容? – Harry

+0

它不會在我的系統上被刪除。你使用的是什麼瀏覽器? – Thariama

+0

FireFox最新。但我想出了另一種方法來使它工作 – Harry