移动 CKEditor 节点时 Javascript DOM 失败
我需要能够在整个网页上交换 CKEditor 富文本区域。我当前的脚本在未应用 CKEditor 时效果很好,但在应用 CKEditor 时无法成功移动文本区域(和输入的文本)。这是一些代码(它需要 ckeditor 才能工作):
<html>
<head>
<title>Sample - CKEditor</title>
<script type="text/javascript" src="/ckeditor/ckeditor.js"></script>
</head>
<body>
<form method="post">
<p>
My Editor:<br />
<a href="#" onclick="swap(this.parentNode.nextSibling.nextSibling, this.parentNode)">first link</a>
<textarea name="editor1"><p>Initial value.</p></textarea>
<script type="text/javascript">
CKEDITOR.replace( 'editor1' );
</script>
</p>
<p>
My Editor2:<br />
<textarea name="editor2"><p>Initial value2.</p></textarea>
<script type="text/javascript">
CKEDITOR.replace( 'editor2' );
</script>
</p>
<p>
<input type="submit" />
</p>
</form>
</body>
</html>
<script>
function swap(from, to){
if(from && to){
var parent = from.parentNode;
var t;
if(parent){
t = parent.removeChild(from);
parent.insertBefore(t, to);
t = null;
}
delete(t);
delete(parent);
}
}
</script>
如果您注释掉 CKEDITOR.replace() 调用,则进行交换没有问题。关于如何解决这个问题有什么建议吗?谢谢。
I need to be able to swap CKEditor rich text areas throughout my webpage. My current script works great when there's no CKEditor applied, but does not successfully move the text area (and entered text) when CKEditor is applied. Here's some code(it needs ckeditor to work):
<html>
<head>
<title>Sample - CKEditor</title>
<script type="text/javascript" src="/ckeditor/ckeditor.js"></script>
</head>
<body>
<form method="post">
<p>
My Editor:<br />
<a href="#" onclick="swap(this.parentNode.nextSibling.nextSibling, this.parentNode)">first link</a>
<textarea name="editor1"><p>Initial value.</p></textarea>
<script type="text/javascript">
CKEDITOR.replace( 'editor1' );
</script>
</p>
<p>
My Editor2:<br />
<textarea name="editor2"><p>Initial value2.</p></textarea>
<script type="text/javascript">
CKEDITOR.replace( 'editor2' );
</script>
</p>
<p>
<input type="submit" />
</p>
</form>
</body>
</html>
<script>
function swap(from, to){
if(from && to){
var parent = from.parentNode;
var t;
if(parent){
t = parent.removeChild(from);
parent.insertBefore(t, to);
t = null;
}
delete(t);
delete(parent);
}
}
</script>
If you comment out the CKEDITOR.replace() calls, there's no problem doing the swap. Any suggestions for how I can fix this? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
事实证明这是一个错误。 http://cksource.com/forums/viewtopic.php?t=18417
Turns out it's a bug. http://cksource.com/forums/viewtopic.php?t=18417
你必须销毁你的 dom 移动的实例,然后再次应用 CKEDITOR
类似
You have to destroy instances do your dom move and then apply CKEDITOR again
something like
这是我的方法,使用 jQuery。
我的上下文:我想将“div1”移到“div2”之后。每个 DIV 都包含一个带有 CKEditor 的文本区域。
然后,将“div1”移动到“div2”之后:
Here is my method, using jQuery.
My context: I want to move "div1" after "div2". Each DIV contains a textarea with CKEditor.
Then, to move "div1" after "div2":