2017-02-15 23 views
0

對於CKeditor,有兩個函數可用於從編輯器獲取數據。CKeditor的getHtml()和getData()之間的區別

在下面的示例中,有一個名爲p_editor的實例,兩個函數的輸出都是相同的。

var p_editor=CKEDITOR.replace('question_editor'); 
$('#PostQuestion').on('click', function() { 
    console.log(p_editor.getData()); 
    console.log(p_editor.document.getBody().getHtml()); 
    console.log(p_editor.document.getBody().getText()); 
}); 

所以我想知道這兩個函數有什麼區別。

回答

0

這兩種方法操作上不同類型的對象:

  • getData()CKEDITOR.editor類的方法。

  • getHtml()CKEDITOR.dom.element類的一種方法。

您的代碼p_editor.document.getBody().getHtml()得到body DOM元素,並在其上執行getHtml()方法。在這種情況下,它與整個編輯器的getData()相同,但是您可以在主體中的另一個dom元素上使用getHtml()並獲取其(部分)HTML。

這裏的文檔: