2015-06-12 35 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