访问x可编辑的动态生成的表单或输入 [英] Access x-editable dynamically generated form or input
问题描述
在单击一个元素时,x可编辑会创建一个input
元素.在validate回调中,如何访问该元素?每次将插件应用于元素时,我都可以通过使用inputclass
分配一个唯一的类来做到这一点,但是,这样做几乎没有灵活性.在回叫中,this
引用原始元素,而不是input
元素.
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);
}
});
推荐答案
我认为这不是最干净的解决方案,但它可以工作.也许根本没有一个干净的解决方案...
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/
这篇关于访问x可编辑的动态生成的表单或输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!