简体   繁体   English

使用javascript生成CKEDITOR不适用于for循环语句

[英]Generating CKEDITOR does not work on for loop statement using javascript

It is possible to create a ckeditor using for loop statement in javascript? 是否可以在JavaScript中使用for循环语句创建ckeditor? Everytime I generate a ckeditor within textarea, the ckeditor is not show up. 每次我在文本区域内生成ckeditor时,该ckeditor都不会显示。 Any idea. 任何想法。 Thank you. 谢谢。

<script type="text/javascript">
 for(var index = 1; index <= 4; index++ ){
  str += '<textarea class="ckeditor" name="answer[]"></textarea>';
 }
</script>

Sample Image: 样本图片: 在此处输入图片说明

Looking at the ckeditor5 readme , it appears that you need to have the HTML textarea(s) already inserted and then call the create method for each textarea, passing its id as the parameter. 查看ckeditor5自述文件 ,您似乎已经需要插入HTML textarea,然后为每个textare调用create方法,并将其id作为参数传递。 I pulled this from the readme: 我从自述文件中删除了此文件:

In your HTML page add an element that CKEditor should replace: 在HTML页面中,添加CKEditor应该替换的元素:

<textarea name="content" id="editor"></textarea>

Load the classic editor build (you can choose between CDN, npm and zip downloads): 加载经典编辑器版本(您可以在CDN,npm和zip下载之间进行选择):

<script src="https://cdn.ckeditor.com/ckeditor5/<version>/classic/ckeditor.js"></script>

Call the ClassicEditor.create() method: 调用ClassicEditor.create()方法:

<script> 
   ClassicEditor .create(
      document.querySelector( '#editor' )
   ) .catch( error => { console.error( error ); } );
</script>

You're ready to go! 您准备好出发了!

So, following those instructions, you should be able to call create for each textarea, in your loop, as long as it's been added to the document before you call create(). 因此,按照这些说明进行操作,只要在调用create()之前将其添加到文档中,就应该可以在循环中为每个文本区域调用create。

Edit: If you really want to use an older version of ckeditor, it looks like a previous question mentions using .replace() or .replaceClass() 编辑:如果您真的想使用旧版本的ckeditor,则看起来像以前的问题提到使用.replace().replaceClass()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM