Ckeditor - 在 div 加载页面后添加 ckeditor (contenteditable="true" )
Ckeditor - add ckeditor after load the page on div (contenteditable="true" )
当我在 div contenteditable="true"
上添加 ckeditor
时,效果很好。有一个 add more
按钮。当我单击该按钮时,添加了 div 但未加载 ckeditor
。我怎样才能让 ckeditor
工作?
创建经典编辑器
您需要做的是为刚刚添加到文档中的每个 div[contenteditable="true"]
调用 CKEDITOR.replace
方法。
您可以通过以下代码实现:
var res = CKEDITOR.document.find( 'div[contenteditable="true"]' ),
// Your editor config goes here.
editorConfig = {};
for ( var i = 0; i < res.count(); i++ ) {
var curElement = res.getItem( i );
if ( !curElement.getEditor() ) {
// We only want to process elements that have have no editor yet.
CKEDITOR.replace( curElement, editorConfig );
}
}
内联编辑器
如果您想改为创建内联编辑器,则需要将 CKEDITOR.replace
替换为 CKEDITOR.inline
。
if ( !curElement.getEditor() ) {
// We only want to process elements that have have no editor yet.
CKEDITOR.inline( curElement, editorConfig );
}
更多阅读:
当我在 div contenteditable="true"
上添加 ckeditor
时,效果很好。有一个 add more
按钮。当我单击该按钮时,添加了 div 但未加载 ckeditor
。我怎样才能让 ckeditor
工作?
创建经典编辑器
您需要做的是为刚刚添加到文档中的每个 div[contenteditable="true"]
调用 CKEDITOR.replace
方法。
您可以通过以下代码实现:
var res = CKEDITOR.document.find( 'div[contenteditable="true"]' ),
// Your editor config goes here.
editorConfig = {};
for ( var i = 0; i < res.count(); i++ ) {
var curElement = res.getItem( i );
if ( !curElement.getEditor() ) {
// We only want to process elements that have have no editor yet.
CKEDITOR.replace( curElement, editorConfig );
}
}
内联编辑器
如果您想改为创建内联编辑器,则需要将 CKEDITOR.replace
替换为 CKEDITOR.inline
。
if ( !curElement.getEditor() ) {
// We only want to process elements that have have no editor yet.
CKEDITOR.inline( curElement, editorConfig );
}