2015-06-12 36 views
0

我有兩個CKEditor,由Liferay腳本在我看來一個接一個地創建。兩者都是分開的div。我想改變它的順序。用CKEditors更改兩個div的順序

我嘗試使用這樣的:

var firstDivWithCKEditor = document.getElementById("firstDivWithCKEditor"); 
var secondDivWithCKEditor = document.getElementById("secondDivWithCKEditor "); 
var parentDiv = secondDivWithCKEditor.parentNode(); 
parent.insertBefore(secondDivWithCKEditor , firstDivWithCKEditor); 

的順序被改變,但這種手術後,我不能做一個主編和參編在前看不見裏面的HTML enything。單擊編輯器中的任何按鈕後,在控制檯上出現錯誤:Uncaught TypeError:無法讀取未定義的屬性'getSelection'。

任何人都知道什麼是錯的?

回答

4

無法使用經典(iframe)編輯器實例執行此操作。您可以輕鬆地重新初始化的情況下,雖然(JSFiddle):

var e1, e2, 
    el1 = CKEDITOR.document.getById('editor1'), 
    el2 = CKEDITOR.document.getById('editor2'); 

function initEditors(reverse) {  
    if (e1 || e2) { 
     e1.destroy(); 
     e2.destroy();   
    } 

    (reverse ? el2 : el1).insertBefore((reverse ? el1 : el2)); 

    e1 = CKEDITOR.replace(el1); 
    e2 = CKEDITOR.replace(el2); 
} 
+0

見http://stackoverflow.com/questions/30494039/ckeditor-loses-content-when-removed-from-dom-and-added-再次/ 30501225#30501225如果您想知道爲什麼無法在DOM中移動編輯器。 – Reinmar