访问x可编辑的动态生成的表单或输入 [英] Access x-editable dynamically generated form or input

查看:73
本文介绍了访问x可编辑的动态生成的表单或输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在单击一个元素时,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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆