Balalala 2011-10-24
今天在修改 OPENCART 的后台时。用Ajax把商品的增添编辑页面调用来。。第一次调入时,一切正常。噩梦从第二次开始。。原来是第一次点击链接,调用内容时,已经进行了一次CKEDITOR的实例化,第二次调入时必然会与第一次的冲突。。
修改:
CKEDITOR.replace('description<?php echo $language['language_id']; ?>', { filebrowserBrowseUrl: 'index.php?route=common/filemanager&token=<?php echo $token; ?>', filebrowserImageBrowseUrl: 'index.php?route=common/filemanager&token=<?php echo $token; ?>', filebrowserFlashBrowseUrl: 'index.php?route=common/filemanager&token=<?php echo $token; ?>', filebrowserUploadUrl: 'index.php?route=common/filemanager&token=<?php echo $token; ?>', filebrowserImageUploadUrl: 'index.php?route=common/filemanager&token=<?php echo $token; ?>', filebrowserFlashUploadUrl: 'index.php?route=common/filemanager&token=<?php echo $token; ?>' });
之前加上
if(CKEDITOR.instances['description<?php echo $language['language_id']; ?>']) { CKEDITOR.remove(CKEDITOR.instances['description<?php echo $language['language_id']; ?>']); }
最后代码
<script type="text/javascript"> <?php foreach ($languages as $language) { ?> if(CKEDITOR.instances['description<?php echo $language['language_id']; ?>']) { CKEDITOR.remove(CKEDITOR.instances['description<?php echo $language['language_id']; ?>']); } CKEDITOR.replace('description<?php echo $language['language_id']; ?>', { filebrowserBrowseUrl: 'index.php?route=common/filemanager&token=<?php echo $token; ?>', filebrowserImageBrowseUrl: 'index.php?route=common/filemanager&token=<?php echo $token; ?>', filebrowserFlashBrowseUrl: 'index.php?route=common/filemanager&token=<?php echo $token; ?>', filebrowserUploadUrl: 'index.php?route=common/filemanager&token=<?php echo $token; ?>', filebrowserImageUploadUrl: 'index.php?route=common/filemanager&token=<?php echo $token; ?>', filebrowserFlashUploadUrl: 'index.php?route=common/filemanager&token=<?php echo $token; ?>' }); <?php } ?> </script>
P.S. 参考 http://www.cnblogs.com/cocowool/archive/2010/09/04/1817989.html
是一道经常出现在前端面试时的问题。如果只是简单的了解new关键字是实例化构造函数获取对象,是万万不能够的。更深入的层级发生了什么呢?同时面试官想从这道题里面考察什么呢?下面胡哥为各位小伙伴一一来解密。