简体   繁体   English

Ckeditor获取元素ID?

[英]Ckeditor get element id?

I am trying to use multiple instances of inline editing in my document. 我正在尝试在文档中使用多个内联编辑实例。 I have figured out how to enable all these instances and save the data of each instance, to a mysql database. 我已经弄清楚了如何启用所有这些实例并将每个实例的数据保存到mysql数据库中。 But I need a way to distuinquish between each editor. 但是我需要一种在每个编辑器之间进行区分的方法。 I was thinking about using id's for this, but then I need to be able to get each elements id when saving, to save that to the database aswell. 我当时正在考虑使用ID,但是随后我需要能够在保存时获取每个元素的ID,并将其也保存到数据库中。 How can I do this? 我怎样才能做到这一点?

This is what I have tried, here is my editors: 这是我尝试过的,这里是我的编辑器:

<div class="row">
   <div contenteditable="true" id="editor1" class="col-md-4 col-md-offset-2 editable">
       <p>Edit me plox</p>
   </div>

   <div contenteditable="true" id="editor2" class="col-md-4 col-md-offset-1 editable">
       <p>Edit me plox</p>
   </div>
</div>

Here is the script that saves the contents of the editors: 这是保存编辑器内容的脚本:

var elements = $( '.editable' );
elements.each( function() {
CKEDITOR.inline(this  ,{
        on:{
            blur: function(event){
                if (event.editor.checkDirty())
                    console.log(event.editor.getData());
                    var data = event.editor.getData();

                    var request = jQuery.ajax({
                        url: "coreedit/scripts/savecontent.php",
                        type: "POST",
                        data: {
                            content : data,
                            id: $(this).attr('id')
                        },
                        dataType: "html"
                    });

                    alert($(this).attr('id'));
            }
        }
    });
} );

This retrieves the id of the ckeditor I guess, because the message it returns is cke_1 and cke_2. 这将检索我猜到的ckeditor的ID,因为它返回的消息是cke_1和cke_2。 I want the actual id's of the elements. 我想要元素的实际ID。 (bump) (凸块)

In the event, this is a CKEditor object ... here are the docs about it 万一this是一个CKEditor对象... 这是关于它的文档

 id: this.element.$.id

DEMO DEMO

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

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