【发布时间】:2011-05-18 10:52:12
【问题描述】:
我使用 jQuery UI 的自动完成功能与它可能创建的用途略有不同。
基本上我想保留所有相同的功能,唯一的区别是当建议框出现时,我不会在用户进行选择时隐藏建议框,我也不希望填充该选择.autocomplete 附加到的输入框。
所以,我一直在阅读 jQuery UI 文档,似乎有一种方法可以禁用 Select: 和 Close: 事件,但我发现他们解释它的方式非常令人困惑,因此,这这就是我在这里寻求帮助的原因。
我的 jQuery
$( "#comment" ).autocomplete({
source: "comments.php",
minLength: 4,
// Attempt to remove click/select functionality - may be a better way to do this
select: function( event, ui ) {
return false;
},
// Attempt to add custom Class to the open Suggestion box - may be a better way
open : function (event, ui) {
$(this).addClass("suggestion-box");
},
// Attempt to cancel the Close event, so when someone makes a selection, the box does not close
close : function (event, ui) {
return false;
}
});
jQuery UI 官方文档
从菜单中选择项目时触发; ui.item 是指选中的项目。 select 的默认操作是将文本字段的值替换为 选定的项目。取消此事件可防止值被更新,但不会 防止菜单关闭。
代码示例
Supply a callback function to handle the select event as an init option.
$( ".selector" ).autocomplete({
select: function(event, ui) { ... }
});
Bind to the select event by type: autocompleteselect.
$( ".selector" ).bind( "autocompleteselect", function(event, ui) {
...
});
混乱
让我感到困惑的是,他们似乎建议删除 .autocomplete 并替换为 .bind("autocompleteselect") - 这将完全禁用自动完成功能?
非常感谢您提供的任何帮助。
【问题讨论】:
标签: jquery-ui autocomplete jquery-ui-autocomplete