[英]jquery ui autocomplete autofocus with category element as first
我正在尝试使用类别时在我的jquery自动完成功能中选择第一项。 现在我的菜单看起来像这样:
[category] <- autofocus selects this one
[item1] <- autofocus should select this one
[item2]
[item3]
[category]
[item4]
[item5]
etc.
我已经尝试过的方法:1.将ui-state-disabled添加到我的类别中2.搜索google如何覆盖menu.next()函数,以便我可以检测到该项目是否是一个类别3.搜索google如何设置选定的类别手动包括触发select事件的元素
到目前为止对我来说没有运气,所以我希望你们有什么建议^^
fidle: http : //jsfiddle.net/uynct53p/5/ (适用于jQuery 1.9,但不适用于1.11)
由于它仍然是输入元素,因此可以在自动完成功能上调用val
方法以设置其值。
由于您要将值设置为data
对象中的第一个元素,因此只需执行
$( "#search" ).autocomplete({ /* ... */ })
.val(data[0].label)
// ...
你的小提琴: http : //jsfiddle.net/uynct53p/7/
回答:Aureltime
这使得类别在jQuery 1.11。*中不可选择。
$.extend($.ui.menu.prototype.options, {
items: "> :not(.ui-autocomplete-category)"
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.