How to get value of CKEditor 5?

前端 未结 3 1157
花落未央
花落未央 2021-01-12 05:13

I want to be able to return the value of the CKEditor textarea, and also write my text inside it.

I used CKEditor 5 CDN. First this my code for the textarea it works

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-12 05:50

    You need to get or save the editor created and then use the getData() function. You can add a .then() on creation to save your editor.

        var myEditor;
    
        ClassicEditor
            .create( document.querySelector( '#editor' ) )
            .then( editor => {
                console.log( 'Editor was initialized', editor );
                myEditor = editor;
            } )
            .catch( err => {
                console.error( err.stack );
            } );
    

    and then get data using

    myEditor.getData();
    

提交回复
热议问题