jQuery自动完成用户界面-我希望它无需用户输入任何内容即可开始进行焦点搜索 [英] jQuery autocomplete UI- I'd like it to start the search onfocus without the user having to type anything

查看:65
本文介绍了jQuery自动完成用户界面-我希望它无需用户输入任何内容即可开始进行焦点搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

jQuery自动完成用户界面-我想开始搜索"onfocus",并在用户使用Tab键或单击搜索字段时立即显示选择列表,而无需用户输入任何内容.

jQuery autocomplete UI - I'd like to start the search "onfocus" and immediately show the list of choices when the user tabs or clicks into the search field without the user having to type anything.

即使我将所需字符数设置为零,默认行为似乎也要求用户输入字符或向下箭头以开始滚球并开始搜索并获取值.

The default behavior seems to requires the user to enter a character or a down arrow to start the ball rolling and start the search and get the values even when I set the number of character required to zero.



$( "#contact" ).autocomplete({
    source: 'remote.php',
    minLength: 0
});

谢谢!

推荐答案

比埃米特的答案要复杂一些,但是...

A bit more complicated than Emmett's answer, but...

  • 即使列表框已经包含文本,也可以使列表突出显示焦点
  • 避免在单击某项后重新弹出列表

这里是:

var closing = false;

$('#contact').autocomplete({
    source: 'remote.php',
    minLength: 0,
    close: function()
    {
        // avoid double-pop-up issue
        closing = true;
        setTimeout(function() { closing = false; }, 300);
    }
})
.focus(function() {
    if (!closing)
        $(this).autocomplete("search");
});

这篇关于jQuery自动完成用户界面-我希望它无需用户输入任何内容即可开始进行焦点搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆