jQuery 自动建议仅适用于两个字段之一

发布于 2024-11-17 10:20:45 字数 792 浏览 3 评论 0原文

我想要两个带有 jquery autosuggest 插件的文本字段。

它在第一个字段中工作得很好:
致电:

$("#cphContent_txtCity").autocomplete({ source: "ClassLibrary/Cities.aspx", minLength: 2, select: function (event, ui) { } }); 

回复:["Munchberg","Muncheberg","Munchen","Munchenbernsdorf","Munchendorf","Munchhouse","Munchsmunster"]

之后我添加了第二个字段(使用不同的 sql 语句复制):
呼叫:

$("#cphContent_txtExpertise").autocomplete({ source: "ClassLibrary/Expertises.aspx", minLength: 2, select: function (event, ui) { } });  

回复:

["Acupressure","Acupuncture"]

当我检查 firebug 时,我可以看到两个字段都会触发呼叫,但只有第一个字段(城市)会给出建议。

我真的看不出有什么问题。也许有人可以指出我正确的方向?

I would like to have two textfields with the jquery autosuggest plugin.

It is working just fine with the first field:
Call:

$("#cphContent_txtCity").autocomplete({ source: "ClassLibrary/Cities.aspx", minLength: 2, select: function (event, ui) { } }); 

Reply:["Munchberg","Muncheberg","Munchen","Munchenbernsdorf","Munchendorf","Munchhouse","Munchsmunster"]

After that I've added a second field (copy with different sql statement):
Call:

$("#cphContent_txtExpertise").autocomplete({ source: "ClassLibrary/Expertises.aspx", minLength: 2, select: function (event, ui) { } });  

Reply:

["Acupressure","Acupuncture"]

When I check with firebug I can see that both fields trigger the call, but only the first field (cities) will give the suggestions.

I really can't see anything wrong with it. Maybe someone could point me in the right direction?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

把回忆走一遍 2024-11-24 10:20:45

确保第二个自动完成返回“值”或“标签”字段,以便 jquery 知道要显示什么。从文档中:

“本地数据可以是一个简单的字符串数组,也可以包含数组中每个项目的对象,具有标签或值属性或两者。标签属性显示在建议菜单中。当用户从菜单中选择某些内容后,该值将被插入到输入元素中。如果只指定一个属性,它将用于两个属性,例如。如果您仅提供值属性,则该值也将用作标签。”

Make sure the second autocomplete is returning a 'value' or 'label' field so jquery knows what to show. From the documentation:

“The local data can be a simple Array of Strings, or it contains Objects for each item in the array, with either a label or value property or both. The label property is displayed in the suggestion menu. The value will be inserted into the input element after the user selected something from the menu. If just one property is specified, it will be used for both, eg. if you provide only value-properties, the value will also be used as the label.”

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文