javascript 未捕获的异常:[CKEDITOR.editor] 实例已经存在
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3606681/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
uncaught exception: [CKEDITOR.editor] The instance already exists
提问by horgen
I've included the CKEditor on my site. Everything works even though I get this JS error:
我在我的网站上包含了 CKEditor。即使我收到此 JS 错误,一切正常:
uncaught exception: [CKEDITOR.editor] The instance "simple_editor" already exists.
未捕获的异常:[CKEDITOR.editor] 实例“simple_editor”已经存在。
The code below is contained inside a PHP file which I include where ever I want the editor. I only have one instance of the editor per page.
下面的代码包含在我想要编辑器的任何地方的 PHP 文件中。我每页只有一个编辑器实例。
<textarea class='ckeditor' id='simple_editor' name='simple_editor'>".$page_content."</textarea>";
<script type="text/javascript">
CKEDITOR.replace( 'simple_editor',
{
height: '110px',
toolbar :
[
['Link','Unlink'],
['Styles','Format','Font','FontSize'],
['Bold','Italic','Underline','Strike'],
['TextColor','BGColor'],
['NumberedList','BulletedList','Outdent','Indent']
]
});
</script>
After some googling I've seen people posting some solution which dosnt work.
经过一些谷歌搜索后,我看到人们发布了一些不起作用的解决方案。
if (CKEDITOR.instances['simple_editor']) { delete CKEDITOR.instances['simple_editor'] };
if (CKEDITOR.instances['simple_editor']) { CKEDITOR.instances['simple_editor'].destroy(); }
Anyone know what to do? :S
有谁知道该怎么办?:S
回答by AlfonsoML
remove class='ckeditor' as it's triggering the automatic replacement system.
删除 class='ckeditor' 因为它正在触发自动替换系统。
回答by Manish
<textarea id="textarea1" name="textarea1" runat="server" ></textarea>
<script>
$(document).ready(function () {
loadEditor('<%= textarea1.ClientID %>');
});
function loadEditor(id) {
var instance = CKEDITOR.instances[id];
if (instance) {
CKEDITOR.remove(instance);
}
CKEDITOR.replace(id, { toolbar: 'Basic' });
}
</script>

