最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to get text from CKEditor 5 using JS or jQuery? - Stack Overflow

programmeradmin9浏览0评论

I have this code to enable CKEditor from their website, but I don't know how to interact with it. How do I get data from it using javascript or jquery?

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

I have this code to enable CKEditor from their website, but I don't know how to interact with it. How do I get data from it using javascript or jquery?

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

Share Improve this question edited Jun 19, 2018 at 6:49 Reinmar 22k4 gold badges69 silver badges79 bronze badges asked Jun 18, 2018 at 14:09 Jirka KastanJirka Kastan 1192 silver badges9 bronze badges 3
  • 1 Have you read the (Docs)[docs.ckeditor./ckeditor5/latest/builds/guides/integration/… about ckEditor? Maybe here is the answer – law_81 Commented Jun 18, 2018 at 14:17
  • Possible duplicate of Get text from CK Editor textarea in JQuery – Troyer Commented Jun 18, 2018 at 14:25
  • Possible duplicate of How to get value of CKEditor 5? – Reinmar Commented Jun 19, 2018 at 6:50
Add a ment  | 

1 Answer 1

Reset to default 5

Please see the changes I have applied to your code snippet.

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./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>

发布评论

评论列表(0)

  1. 暂无评论