简体   繁体   English

使用Jquery自动完成功能时如何删除筛选条件并在“文本输入”字段的焦点上显示数据

[英]How to remove filter criteria and display data on focus of a Text Input field when using Jquery Autocomplete feature

This is a program which is responsible to display autosuggestions . 这是一个负责显示自动建议的程序。

When i keep the focus inside the tags input field , it should display all the available data present inside the source , (i don't need any filter criteria ) 当我将焦点保持在标签输入字段内时,它应显示源内部存在的所有可用数据(我不需要任何过滤条件)

On focus of the text input field it should display all the data 在文本输入字段的焦点上,它应该显示所有数据

This is my jsfiddle 这是我的jsfiddle

http://jsfiddle.net/n30bku6v/1/ http://jsfiddle.net/n30bku6v/1/

$(document).on('focus', '#tags', function() {
    $( "#tags" ).autocomplete({
      source: availableTags
    });
});    

Could you please tell me how to do this 你能告诉我怎么做吗

I think first of all you should bring your autocomplete initialization out of onFocus callback, so it won't initialize on each focus event. 我认为首先您应该将autocomplete初始化从onFocus回调中onFocus ,因此不会在每个焦点事件上进行初始化。

To achieve your desired behavior, you could use minLength property and search method, like this: 为了实现所需的行为,可以使用minLength属性和search方法,如下所示:

$(function(){
    $("#tags").autocomplete({
        source: availableTags,
        minLength: 0
    });

    $(document).on('focus', '#tags', function() {
        $("#tags").autocomplete("search","");
    });    
});

Using minLength we say to autocomplete to work even when there is no query, and search method is used to trigger autocomplete with empty query. 我们说使用minLength可以使自动完成功能即使在没有查询的情况下也能正常工作,并且search方法用于触发带有空查询的自动完成功能。

Working demo. 工作演示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在jquery ui自动完成的自定义数据中删除焦点并显示 - How to remove the focus in the jquery ui autocomplete custom data and display 如何使用 jQuery 在页面加载时关注表单输入文本字段? - How to focus on a form input text field on page load using jQuery? 使用jQuery自动完成功能的输入字段有时会在键入时失去焦点(仅在IE 11上发生) - Input field, using jQuery autocomplete, sometimes loses focus when typing ( only happens on IE 11) 如何使用jQuery在输入字段后删除/更改/替换文本 - how to remove/change/replace text after input field using jquery 如何使用jquery专注于带有值的输入文本? - How to focus on an input text with a value using jquery? jQuery:如何关注输入文本字段,以便将光标放在文本的末尾? - jQuery: How to focus on input text field such that the cursor is placed at the end of the text? 当用户使用Jquery清除文本字段并将焦点移出文本字段时,如何触发事件? - How to trigger an event when the user clears the text field and focus out of the text field using Jquery? 使用jQuery过滤和删除没有数据的输入 - Using jQuery to filter and remove input with no data jQuery 自动完成过滤表的输入字段 - jQuery Autocomplete a input field for a filter table 使用Jquery关注输入并移除焦点 - Focus on input and remove focus using Jquery
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM