- 獲取ckeditor對象
CKEDITOR.instances.ckeditor_name
- 獲取ckeditor中的值和插入內(nèi)容
CKEDITOR.instances.message.insertHtml(''); //插入html內(nèi)容
//獲取CKEditor的值
var editor=CKEDITOR.replace( 'editor1' );
editor.document.getBody().getText(); //取得純文本
editor.document.getBody().getHtml(); //取得html文本
CKEDITOR.instances.content.getData()=="")
//content是textarea的name
//設(shè)置CKEditor的值
CKEDITOR.instances.content.setData("CCCTO");
var editor = CKEDITOR.replace("content");
editor.setData("CCCTO");
//在編輯器中禁止粘貼
editor.on('paste', function() {
return false;
});
//或者
editor.on('instanceReady', function(e) {
editor.on('paste', function() {
return false;
});
});
//在 instanceReady中 綁定事件才可用
//需要新建實例,假若CKEditor實例已存在
if (CKEDITOR.instances['textarea_name']){
CKEDITOR.instances['textarea_name'].destroy();
}
CKEDITOR.replace('textarea_name');
function loadEditor(id)
{
var instance = CKEDITOR.instances[id];
if(instance)
{
CKEDITOR.remove(instance);
}
CKEDITOR.replace(id);
}
var instance = CKEDITOR.instances['test'];
if (instance) {
CKEDITOR.remove(CKEDITOR.instances['test']);
}
if(CKEDITOR.instances[editorName])
delete CKEDITOR.instances[editorName];
CKEDITOR.replace(editorName);
- 在js中配置ckeditor
let configuration = {
toolbar: "Full" ,
filebrowserImageUploadUrl: appConfig.API_UPLOADIMAGES_BASE_URL + "uploadImageForRest" ,
newButtonImageUploadUrl: appConfig.API_UPLOADIMAGES_BASE_URL + "uploadImage"
};
CKEDITOR.replace(this.elementName, configuration);
CKEDITOR.instances[this.elementName].on("change", function () {
let data = CKEDITOR.instances[this.elementName].getData();
this.props.onChange(data);
}.bind(this));
}
- 獲取ckeditor配置信息
CKEDITOR.instances.ckeditor_name.config.toolbar
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。