问题
Upon clicking an element, x-editable creates an input
element. Within the validate callback, how can I access that element? I "could" do so by assigning a unique class using inputclass
to each time the plugin is applied to an element, however, this offers very little flexibility. Within the call back, this
references the original element, not the input
element.
https://jsfiddle.net/cgym6m3v/1/
<p>Name</p><a href="javascript:void(0)" id="name"></a>
$('#name').editable({
type: 'text',
title: 'Name',
url: '/echo/json/',
pk: 123,
validate: function (value) {
console.log(this,value);
}
});
回答1:
I don't think this is the cleanest solution, but it will work. Maybe there isn't a clean solution at all...
$('.bla').editable({
inputclass: function(e, f) {
$("a[aria-describedby=" + $(this).closest(".ui-tooltip").prop("id") + "]").data("shared", this);
},
validate: function (value) {
console.log("validate", $(this).data("shared"));
}
});
https://jsfiddle.net/cgym6m3v/5/
来源:https://stackoverflow.com/questions/29566417/access-x-editable-dynamically-generated-form-or-input