在动态添加的文本上使用内联CKEditor [英] Using inline CKEditor on dynamically added text

查看:150
本文介绍了在动态添加的文本上使用内联CKEditor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建立一个网路应用程式,使用javascript来动态添加元素到页面,然后可以使用 contentEditable =true CKEditor

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.

目前,如果我添加一个元素到页面 contentEditable =true,元素是可编辑的,但 CKEditor 工具栏不出现。

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

c $ c> CKEDITOR.inlineAll()但这似乎没有做任何事情。

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

如何激活 CKEditor 在动态创建的元素上进行行内编辑? (不刷新页面)。

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

编辑:我发现给元素一个ID(例如)someId和调用CKEDITOR.inline 。但我不想为我的所有元素添加唯一的ID。有没有办法激活CKEditor对所有contentEditable元素?

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?

推荐答案

CKEDITOR.inline 接受本机DOM元素作为参数。不管你如何创建动态元素,如果你传递一个对该函数的引用,它会将其转换为CKEditor实例。例如,假设您使用jQuery作为主框架:

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 ) ); 

请参阅小提琴

这篇关于在动态添加的文本上使用内联CKEditor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆