CKEditor 不显示在 JS 文件中

CKEditor not displayed in JS file

我想将 textarea 显示为 CKEditor,但它在这里不起作用,尽管它在我的 html 代码中起作用。

我有一个文件 global.js,我也将其作为脚本包含在我的 html 代码中。

这是我在 global.js

中的功能
$(document).ready(function() {
$("a#reply").one("click" , function() {
    var comCode = $(this).attr("name");
    var parent = $(this).parent();
    parent.append("<br /><form action='index.php' method='post'><input 
       type='text' name='uname2' id='uname2' placeholder='Enter username' 
       required /><textarea class='ckeditor' name='editor' 
       placeholder='Enter your query' id='new-reply' required></textarea>
       <input type='hidden' name='code' value='"+comCode+"' /><input 
       type='submit' class='form-submit' id='form-reply' name='new_reply' 
       value='Reply' /></form>")
       //$(".chreply").toggle();
    });
 })

我什至试过包括:

CKEDITOR.scriptLoader.load( this.path + 'ckeditor/ckeditor.js' );
CKEDITOR.replace( 'ckeditor' );

我是不是做错了什么?是我的代码有问题还是 ckeditor 从未显示在 js 文件中?

CKEDITOR.replace 只能与 DOM 元素、元素 ID 或元素名称一起使用。从我在您的代码中看到的情况来看,您尝试将它与 class 名称一起使用。所以在这个简短的例子中你应该使用这样的代码:

CKEDITOR.replace( 'new-reply' )

很可能是控制台中出现错误,提示找不到 ckeditor 或类似的东西。

它通过添加

来工作
parent.append("<br /><form action='index.php' method='post' id='tog'><input 
type='text' name='uname2' id='uname2' placeholder='Name' required /><textarea 
name='editor' placeholder='Query' id='new-reply' required>
</textarea><input type='hidden' name='code' value='"+comCode+"' /><input 
type='submit' class='form-submit' id='form-reply' name='new_reply' 
value='Reply' /><script>CKEDITOR.replace('new-reply');</script></form>")