首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CKEditor 4可以工作,但CKEditor 5不能

CKEditor 4可以工作,但CKEditor 5不能
EN

Stack Overflow用户
提问于 2020-02-06 04:40:02
回答 1查看 409关注 0票数 0

这是可行的:

代码语言:javascript
复制
<!DOCTYPE html>
<html lang="en">
<head>
    <title>CKEditor Classic Editing Sample</title>
    <!-- Make sure the path to CKEditor is correct. -->
    <script src="scripts/ckeditor/ckeditor.js"></script>
    <!-- this is with CKEDITOR 4 -->
    <script>
      window.addEventListener("load", function() {
        CKEDITOR.replace ('editor1');
      });
    </script>
</head>
<body>
    <form method="post">
        <p>
            My Editor:<br>
            <textarea name="editor1" id="editor1">&lt;p&gt;Initial editor content.&lt;/p&gt;</textarea>
        </p>
        <p>
            <input type="submit">
        </p>
    </form>
</body>
</html>

但是完全相同的超文本标记语言,脚本路径更改为CKEditor 5,<textarea>不会被替换:

代码语言:javascript
复制
<!DOCTYPE html>
<html lang="en">
<head>
    <title>CKEditor Classic Editing Sample</title>
    <!-- Make sure the path to CKEditor is correct. -->
    <script src="scripts/ckeditor5-build-classic/ckeditor.js"></script>
    <!-- this is with CKEDITOR 5 -->
    <script>
      window.addEventListener("load", function() {
        CKEDITOR.replace ('editor1');
      });
    </script>
</head>
<body>
    <form method="post">
        <p>
            My Editor:<br>
            <textarea name="editor1" id="editor1">&lt;p&gt;Initial editor content.&lt;/p&gt;</textarea>
        </p>
        <p>
            <input type="submit">
        </p>
    </form>
</body>
</html>

我下载了CKeditor 5压缩文件并解压缩到指定的路径。在第二种情况下,chrome error控制台显示:

代码语言:javascript
复制
Uncaught ReferenceError: CKEDITOR is not defined

我错过了什么?

EN

回答 1

Stack Overflow用户

发布于 2020-02-06 05:10:41

因此,我最终在CKEditor网站上找到了相关文章:https://cdn.ckeditor.com/#ckeditor5

v5应用编程接口需要不同的语法:

代码语言:javascript
复制
<!DOCTYPE html>
<html lang="en">
<head>
    <title>CKEditor Classic Editing Sample</title>
    <!-- Make sure the path to CKEditor is correct. -->
    <script src="https://cdn.ckeditor.com/ckeditor5/16.0.0/classic/ckeditor.js"></script>
    <script>
    window.addEventListener("load", function() {
      ClassicEditor
           .create( document.querySelector( '#editor' ) )
           .then( editor => {
                   console.log( editor );
           } )
           .catch( error => {
                   console.error( error );
           } );
    });
    </script>
</head>
<body>
  <div id="editor">This is some sample content.</div>
</body>
</html>

也许只有我这样认为,但我认为基本的“入门”指南可能会更好。在我将初始化代码放入事件侦听器之前,我也得到了v5的错误。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60083777

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档