admin管理员组文章数量:1426023
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. 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. 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. I want the actual id's of the elements. (bump)
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. 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. 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. I want the actual id's of the elements. (bump)
Share Improve this question edited Apr 8, 2014 at 18:03 user3511194 asked Apr 8, 2014 at 13:37 user3511194user3511194 231 silver badge5 bronze badges 1-
it's just a guess but you can try
$(this).parent().attr('id')
... or you could inspect the dom tree in order to point to the right element ... read more about traversing – rafaelcastrocouto Commented Apr 8, 2014 at 18:09
1 Answer
Reset to default 4In the event, this
is a CKEditor object ... here are the docs about it
id: this.element.$.id
DEMO
本文标签: javascriptCkeditor get element idStack Overflow
版权声明:本文标题:javascript - Ckeditor get element id? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745417242a2657741.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论