简体   繁体   English

CKEditor-如何从最初未分配ID的ckeditor元素获取数据

[英]CKEditor - How do I get the data from a ckeditor element that was not assigned an ID initially

I just started using CKEditor, and I went through the API Documentation, which was really good, though there was some stuff left out. 我刚开始使用CKEditor,并且浏览了API文档,这很不错,尽管遗漏了一些东西。 At some point their help or documentation takes you to a page and says to post questions and look for answers on it on StackOverflow, so here I am. 在某些时候,他们的帮助或文档将您带到某个页面,并说要在StackOverflow上发布问题并寻找答案,所以我在这里。

In the documentation, it does say how to get the data or to look for changes based on an elements ID. 在文档中,它确实说明了如何获取数据或根据元素ID查找更改。 I have a page that the elements being created on it are dynamically generated and are not getting an ID as they are being dynamically generated. 我有一个页面,该页面上动态创建的元素是动态生成的,因为它们是动态生成的,所以没有获取ID。 These elements are textarea and <div contenteditibable='true' . 这些元素是textarea<div contenteditibable='true' I know when CKEditor does its thing, it will create an ID on certain parts of the elements as well. 我知道CKEditor做事时,也会在元素的某些部分上创建一个ID。 I know in HTML everything gets an ID in the DOM. 我知道HTML中的所有内容都会在DOM中获得ID。 And I know that I am oversimplifying things. 而且我知道我在简化事情。

Using CKEditor, how do I get the data or change event from something I don't know the ID for? 使用CKEditor,如何从我不知道其ID的地方获取数据或更改事件?

Please see the source code for inlineall sample. 请查看inlineall示例的源代码。 There is a pretty smart event used which allows you getting to each editor instance (when it is created) and its element. 使用了一个非常智能的事件 ,它使您可以进入每个编辑器实例(创建时)及其元素。 Inside that event listener you can change initial editor configuration (with the help of other event to be more precise). 在该事件侦听器内,您可以更改初始编辑器配置(借助其他事件的帮助,可以更精确)。

Editor has also instanceReady event which you can use in the same way to assign change event that will capture all changes for particular editor instance. 编辑器还具有instanceReady事件,您可以以相同的方式使用它来分配更改事件 ,该事件将捕获特定编辑器实例的所有更改。 Finally inside the change event listener (as well as other editor events ), you can get access to editor for which the event was fired eg 最后,在更改事件侦听器(以及其他编辑器事件 )中,您可以访问对其触发了事件的编辑器,例如

CKEDITOR.on( 'instanceReady', function( evt ) {
     evt.editor.on( 'change', function( e ) {
        console.log( e.editor );
        console.log( e.editor.element );
     } );
} );

Hope this helps you get started. 希望这可以帮助您入门。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM