gpt4 book ai didi

javascript - 'focus'什么时候调用 'autocomplete'

转载 作者:行者123 更新时间:2023-11-29 22:21:10 24 4
gpt4 key购买 nike

来自 http://jqueryui.com/demos/autocomplete/ 的“焦点”文档状态:

focusType:autocompletefocus Before focus is moved to an item (not selecting), ui.item refers to the focused item. The default action of focus is to replace the text field's value with the value of the focused item, though only if the focus event was triggered by a keyboard interaction. Canceling this event prevents the value from being updated, but does not prevent the menu item from being focused.

Code examples

Supply a callback function to handle the focus event as an init option. $( ".selector" ).autocomplete({ focus: function(event, ui) { ... } }); Bind to the focus event by type: autocompletefocus. $( ".selector" ).bind( "autocompletefocus", function(event, ui) { ... });

使用下面的代码在所有自动完成元素上设置一个名为“mytag”且值为“tester”的属性,即使我没有选择这些元素。为什么只有在聚焦其中一个下拉菜单时才添加属性“focus”,而不是在加载页面时添加?

 $("#myDiv").autocomplete({
source: availableTags,
focus: function(event, ui) {
$(".ui-autocomplete li").attr("mytag", "tester");
}
});

最佳答案

将鼠标悬停在建议的完成项上或使用箭头键选择完成项时。这是一个普通的“焦点”,应用于自动完成框。
自己试试:http://jsfiddle.net/qk9gv/ !

关于javascript - 'focus'什么时候调用 'autocomplete',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12391627/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com