我正在将CKEditor用于我网站的博文,但是在通过.load()
加载所有沼泽帖后,他们不再被CKEditors替换了。
这是完成的例子:
$("#container #postholder").load("http://url.com/viewblog.php?id=155 #container #postholder");
首先,我遇到了通过.load()
方法加载的项目调用的脚本问题。我通过更改按钮调用来解决这个问题:
$(document).on('click','.edity',function(){ });
按钮现在有效,但CKEditor不是。
假设我在页面上有5个不同的实例,它们都具有ckeditor
的泛型类,所以它们都可以工作。
但是,在.load()
项之后,它们不会更改为CKEditors,而是保留文本区域。
要解决此问题,我在点击“修改”按钮时尝试了此操作:
$(document).on('click','.edity',function(){
CKEDITOR.replace('.ckeditor');
});
这不起作用,然后我尝试使用CKEditors的名称:
$(document).on('click','.edity',function(){
CKEDITOR.replace('editorName');
});
即使在.load()
之后,这仍然有效,但它仅适用于第一个实例。所有其他CKEditor都没有更改为CKEditor。
我无法看到如何解决这个问题......
任何人都明白吗?
编辑器的创建方式如下:
这是每个博客帖子结果的foreach循环。 ckEID变量是帖子ID + 1。
<div class="editor">
<textarea name="muffin" id="'.$ckEID.'" class="ckeditor">'.$text.'</textarea>
</div>
我用这个:
$(document).on('click','.edity',function(){
$(this).parent().find('.editor').toggle();
CKEDITOR.replace('ckeditor');
});
单击编辑按钮时转换文本区域。
尝试使用replaceAll,错误控制台显示例如。
uncaught exception: The editor instance "message" is already attached to the provided element.
我在页面上有其他文本区域,使用replaceAll时似乎一切都搞砸了。