Jquery ui Jquery自动完成选择名称和显示id
我正在表单中使用自动完成jquery插件。在这种情况下,当我搜索姓名时,自动完成显示姓名列表选择要列出的姓名在输入字段中显示姓名。当我选择名字的时候,我想要onselection,它会在输入框中显示名字的id。请告诉我怎么做或者任何jquery插件 谢谢这是Jquery代码:Jquery ui Jquery自动完成选择名称和显示id,jquery-ui,jquery,jquery-plugins,jquery-selectors,Jquery Ui,Jquery,Jquery Plugins,Jquery Selectors,我正在表单中使用自动完成jquery插件。在这种情况下,当我搜索姓名时,自动完成显示姓名列表选择要列出的姓名在输入字段中显示姓名。当我选择名字的时候,我想要onselection,它会在输入框中显示名字的id。请告诉我怎么做或者任何jquery插件 谢谢这是Jquery代码: $("#txt1").autocomplete({ source: function (request, response){ $.ajax({ type: "POST",
$("#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"}]
我测试过了,效果很好
祝你好运。Foroughi这是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"}]
我测试过了,效果很好
祝你好运。如果你是Asp.NETWebForm,你的方法(或者更好的说法是WebMethod)的结果将显示在data.d中。当你使用asp.NETMVC时,它没有意义。谢谢,它可以工作。但是jQueryAPI文档中没有提到此方法。如果您是Asp.NETWebForm,则方法的结果(或者更好的说法是WebMethod)将显示在data.d中。当你使用asp.NETMVC时,它没有意义。谢谢,它可以工作。但是这个方法并没有在jQueryAPI文档中提到。