jQuery Editable ID number
I am new to jQuery and I am trying to use editable. I want to use the id of the the div tag as the entries are taken from a database and I need the id of each so that when I save the info I can reference it. how can I carry the id number? This is my 开发者_C百科code:
<script language="javascript" type="text/javascript">
$(document).ready(
function()
{
$('div.EditName').editable({
type:'text',
id : 'elementid',
submit:'save',
cancel:'cancel',
onSubmit:SaveName
})
function SaveName(content,elementid)
{
alert(content.current);
alert(elementid);
}
});
HTML code:
<div style="width:80%" class="EditName" id="Name7268">David Price</div>
at this point I just want to display the alert containing the Edited david price and the id number of the div tag.
editable's onSubmit
callback takes the following form (though omitting the arguments, as you did, is valid):
function foo(content) { }
Within this function, this
is a jQuery object representing the DOM node in question; you can obtain the ID from that.
editable's options do not include an id
field. Take a look at the documentation.
Also, you have a syntax error.
function SaveName(content) {
alert(content.current);
alert(this.attr('id'));
}
$(function() { // handy shortcut
$('div.EditName').editable({
type: 'text',
submit: 'save',
cancel: 'cancel',
onSubmit: SaveName
}); // you'd missed out this semicolon
});
I reckon you should check the newer version of Editable at http://www.tectual.com.au/posts/7/jQuery-Editable-Plugin-Best-In-Place-Editor-.html
In this new version there is an Event function onFreeze and another method beforeFreeze. using these functions you have access to editable input and display element and you can do whatever you want.
精彩评论