本文介绍了jQuery自动完成选择名称和显示ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在表单中使用自动完成的jquery插件.在这种情况下,当我搜索名称时,自动完成功能将在选择名称时显示名称列表,以列出名称,从而在输入字段中显示名称.当我选择名称时,我希望onselection在输入字段中显示名称的ID.请让我知道我该如何做或使用任何jquery插件?
谢谢
解决方案这是Jquery代码:
$("#txt1").autocomplete({ source: function (request, response){ $.ajax({ type: "POST", url: "YourAddress", contentType: "application/json; charset=utf-8", dataType: "json", success: function (data) { response($.map(data.d, function (item) { return { id: item.Value, value: item.Text } })) } }); }, select: function (event, ui) { $("#hdnId").val(ui.item.id);//Put Id in a hidden field } });调用ajax请求并返回JSON数据,如下所示:
[{"Value":val1,"Text":"text1"}, {"Value":val2,"Text":"text2"}]我测试了它.很棒的人
祝你好运.
I am using the autocomplete jquery plugin in my form. In this when I search the name , autocomplete display the list of the names onselection the names to list it display the name in the input field. I want onselection when I select the name it display the id of the name in input field.Please let me know How can I do it or any jquery plugin ?
Thanks
解决方案this is Jquery Code :
$("#txt1").autocomplete({ source: function (request, response){ $.ajax({ type: "POST", url: "YourAddress", contentType: "application/json; charset=utf-8", dataType: "json", success: function (data) { response($.map(data.d, function (item) { return { id: item.Value, value: item.Text } })) } }); }, select: function (event, ui) { $("#hdnId").val(ui.item.id);//Put Id in a hidden field } });call you ajax request and return JSON data something like this :
[{"Value":val1,"Text":"text1"}, {"Value":val2,"Text":"text2"}]I tested it.It works great man
Good luck.Foroughi
更多推荐
jQuery自动完成选择名称和显示ID
发布评论