jQuery自动完成minLength和返回值

时间:2011-08-27 13:43:05

标签: jquery autocomplete

我正在实现自动完成功能,但是它在第一个按键上启动,并且还将值返回到文本框,我不想要它,因为我正在使用它作为防止重复的方法。

我正在使用jQuery 1.6。

有关如何纠正这个的想法吗?

$("#groupname").autocomplete("resources/getallgroups.php", {
    minLength: 2,
    select: function(event, ui) {
        return false;
    }
});

2 个答案:

答案 0 :(得分:1)

您使用的是什么自动填充库?最好的一个是jQuery UI,在这种情况下你想要将代码更改为:

$("#groupname").autocomplete({
    source: "resources/getallgroups.php",
    minLength: 2,
    select: function(event, ui) {
        return false;
    }
});

所有文档都在这里:http://jqueryui.com/demos/autocomplete/

答案 1 :(得分:0)

认为这应该是一个单独的答案......

根据documentation minLength应该是minChars。此外,我没有在任何地方看到选择回调的选项,但您可以像这样使用result事件:

$("#groupname").autocomplete("resources/getallgroups.php", {
  minChars: 2
}).result(function(event, data, formatted) { 
  return FALSE;
});

希望有所帮助

相关问题