鍍金池/ 問答/HTML5  HTML/ CKEditor5富文本編輯器如何取值

CKEditor5富文本編輯器如何取值

html中引入了CKEditor5的js代碼,然后通過下面代碼綁定到textarea元素上面。

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

然后js的方式就不能獲取到textarea的文本節(jié)點(diǎn),查看CKEditor的API問題,發(fā)現(xiàn)可以通過editor.getData()獲??;但是只能剛加載的時(shí)候獲取,如何做到,點(diǎn)擊某個(gè)按鈕就能拿到文本框內(nèi)容呢?

回答
編輯回答
哎呦喂

有木有人咧!??!

2018年5月19日 23:07
編輯回答
陪她鬧

ClassicEditor

    .create( document.querySelector( '#editor' ), {  
        //工具欄,可選擇添加或去除
        toolbar: ['headings', 'bold', 'italic', 'blockQuote', 'bulletedList', 'numberedList', 'link', 'cut','undo','redo'],
        //toolbar: ['headings', 'bold', 'italic', 'blockQuote', 'bulletedList', 'numberedList', 'link', 'ImageUpload', 'cut','undo','redo'],
        //editor加載中文簡體,默認(rèn)是英文
        language: 'zh-cn' 
        //,ckfinder: {
        //    uploadUrl: '/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files&responseType=json'
        //}
        //image: {
        //    // You need to configure the image toolbar, too, so it uses the new style buttons.
        //    toolbar: [ 'imageTextAlternative', '|', 'imageStyle:alignLeft', 'imageStyle:full', 'imageStyle:alignRight' ],

        //    styles: [
        //        // This option is equal to a situation where no style is applied.
        //        'full',

        //        // This represents an image aligned to the left.
        //        'alignLeft',

        //        // This represents an image aligned to the right.
        //        'alignRight' ,

        //        'side'
        //    ]
        //},
    } )
    .then( editor => {
        window.editor = editor;
} )
    .catch( err => {
        console.error( err.stack );
} );

 
var a = document.getElementById("editor"); //取得純文本

alert(a.innerHTML);
alert(a.textContent);
2017年11月30日 03:49