一页上有多个自动完成功能且具有一种功能?
有没有一种方法可以在一页上拥有多个自动完成文本字段,所有下拉列表中都有不同的数据,但都使用一个功能?即不为每一个重复下面的代码?
我尝试在 $().autocomplete{}
中使用 $(this)
但它不喜欢它。我想我可以有一个隐藏字段,其中包含控制器目标,其中包含所有结果。让它对所有人都有效,但每个输入都具有与按类工作相同的结果。
或者是否有更好的方法来进行多个自动完成,每个自动完成具有不同的下拉数据?
$(".ac_input").autocomplete(
base_url + $(".ac_input").siblings("input[name=goto]").val(),
{
delay:10,
minChars:1,
matchSubset:1,
matchContains:1,
cacheLength:10,
onItemSelect:selectItem,
onFindValue:findValue,
formatItem:formatItem,
autoFill:false,
maxItemsToShow:10
}
);
is there a way to have more than one autocomplete text field on a page, all with different data in the drop down but all use one function? i.e. not repeat the code below for each one?
I've tried using $(this)
inside the $().autocomplete{}
but it doesn't like it. I was thinking i could have a hidden field with the controller destination in that holds all the results. Got it working for all but each input has the same results as it is working by class.
OR is there a better way to have multiple autocompletes each with different dropdown data?
$(".ac_input").autocomplete(
base_url + $(".ac_input").siblings("input[name=goto]").val(),
{
delay:10,
minChars:1,
matchSubset:1,
matchContains:1,
cacheLength:10,
onItemSelect:selectItem,
onFindValue:findValue,
formatItem:formatItem,
autoFill:false,
maxItemsToShow:10
}
);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您始终可以自己构建它:总体思路是将您希望自动完成显示的所有数据保留在 << 中。 ul>并隐藏 <力>与您输入的内容不匹配的元素。之后,您所需要的只是一些定位和样式,瞧!
这是我编写的页面的示例。
JS
PHP
CSS
You can always build it yourself: The general idea is to keep all the data you want the autocomplete to display in a < ul > and hide the < li > elements that don't match what you've entered. After that, all you need is some positioning and styling and voila!
Here is an example of a page I've written.
JS
PHP
CSS