使用jQuery自动完成小部件,如何在选择后用我自己的数据填充输入值 [英] With jquery autocomplete widget, how to populate the input value after a selection with my own data

查看:89
本文介绍了使用jQuery自动完成小部件,如何在选择后用我自己的数据填充输入值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的表单文本输入栏中,自动完成窗口小部件返回的json将是[{id = 1,lable ="lable1"},......]

In my form text input bar, the json returned by the autocomplete widget will be, [{id = 1,lable="lable1"},......]

[{id = 1,label="label1"},{id = 2, label="label2"},......]

并且我希望输入框的显示值是默认的标签",但是我希望在提交表单时将输入值显示为"id".

and I want the input box display value to be "label" which works as default, but I want to the input value to be "id" when I submit the form..

非常感谢!

推荐答案

我通常会保留< input type ='hidden'>在自动完成输入旁边,然后在完成的选择事件上,我用ID填充它:

I usually keep a <input type='hidden'> right next to the autocomplete input, and then on the select event of the complete I populate that with the ID:

 $("#autocomplete-input").autocomplete({
            minLength: 2,
            select: function (event, ui) {
                $("#autocomplete-input-id").val(ui.item.id);
            }

        }); 

这篇关于使用jQuery自动完成小部件,如何在选择后用我自己的数据填充输入值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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