Using inline CKEditor on dynamically added text

喜夏-厌秋 提交于 2019-12-21 17:32:35

问题


I am building a web app that uses javascript to dynamically add elements to the page, that can then be edited using contentEditable="true" and CKEditor.

Currently if I add an element to the page with contentEditable="true", the element is editable but the CKEditor toolbar is not appearing.

I have tried calling CKEDITOR.inlineAll() but this doesn't seem to do anything.

How can I activate CKEditor inline editing on dynamically created elements? (Without refreshing the page).

EDIT: I have found that giving the element an ID of (e.g.) someId and calling CKEDITOR.inline(someId) has the desired effect. But I don't want to have to add unique IDs to all of my elements. Is there a way to activate CKEditor on all contentEditable elements?


回答1:


CKEDITOR.inline accepts a native DOM element as a parameter. No matter how you create dynamic elements, if you pass a reference to that function, it will convert it into CKEditor instance. For example, assuming that you use jQuery as a main framework:

// A dynamically created element.
var el = $( '<p contenteditable="true">I\'m editable!</p>' );

// Append the element to <body>.
$( 'body' ).append( el );

// CKEDITOR.inline accepts DOM element as parameter.
CKEDITOR.inline( el.get( 0 ) ); 

See the fiddle.



来源:https://stackoverflow.com/questions/18616119/using-inline-ckeditor-on-dynamically-added-text

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!