如何使用 JS 或 jQuery 从 CKEditor 5 获取文本?

How to get text from CKEditor 5 using JS or jQuery?

我有这段代码可以从他们的网站上启用 CKEditor,但我不知道如何与之交互。如何使用 javascript 或 jquery 从中获取数据?

ClassicEditor
  .create(document.querySelector('#editor'))
  .then(editor => {
    console.log(editor);
  })
  .catch(error => {
    console.error(error);
  });
<script src="https://cdn.ckeditor.com/ckeditor5/10.0.1/classic/ckeditor.js"></script>
<textarea name="content" id="editor">
<p>Here goes the initial content of the editor.</p>
</textarea>

请查看我对您的代码片段所做的更改。

let theEditor;

ClassicEditor
  .create(document.querySelector('#editor'))
  .then(editor => {
    theEditor = editor;

  })
  .catch(error => {
    console.error(error);
  });


function getDataFromTheEditor() {
  return theEditor.getData();
}

document.getElementById('getdata').addEventListener('click', () => {
  alert(getDataFromTheEditor());
});
<script src="https://cdn.ckeditor.com/ckeditor5/10.0.1/classic/ckeditor.js"></script>
<textarea name="content" id="editor">
<p>Here goes the initial content of the editor.</p>
</textarea>
<button id="getdata">Print data</button>