jQueryUI 自动完成 - 选择后模糊字段

发布于 2024-11-09 09:52:59 字数 477 浏览 0 评论 0原文

我希望能够在从下拉列表中选择一个值后模糊该字段。我目前的焦点是自动完成项目搜索。

这是我所拥有的:

            $("#season").autocomplete({  
            source: function( request, response ) {
                    $.getJSON( "search.asp", {
                        term: request.term,
                        type: 'season'
                        }, response );},
            minLength: 0
        }).focus(function(event, ui){
            $(this).autocomplete("search","");
        });

I would like to be able to blur the field after I select a value from the dropdown. I currently have the autocomplete item searching on focus.

Here is what I have:

            $("#season").autocomplete({  
            source: function( request, response ) {
                    $.getJSON( "search.asp", {
                        term: request.term,
                        type: 'season'
                        }, response );},
            minLength: 0
        }).focus(function(event, ui){
            $(this).autocomplete("search","");
        });

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

忆伤 2024-11-16 09:52:59

您可以使用“close”方法在输入字段上调用模糊:

$("#season").autocomplete({   
   source: function(request, response){      
   $.getJSON("search.asp", {
         term: request.term,
         type: 'season'
      }, response);
   },
   minLength: 0,
   close: function(){
      $(this).blur();
   }}).focus(function(event, ui){
   $(this).autocomplete("search", "");
});

You could use the 'close' method to call blur on the input field:

$("#season").autocomplete({   
   source: function(request, response){      
   $.getJSON("search.asp", {
         term: request.term,
         type: 'season'
      }, response);
   },
   minLength: 0,
   close: function(){
      $(this).blur();
   }}).focus(function(event, ui){
   $(this).autocomplete("search", "");
});
孤凫 2024-11-16 09:52:59

自动完成有一个选择事件,当您从下拉列表中选择某些内容时会触发该事件。在这种情况下,您可以在输入上调用 .autocomplete('close') 来关闭下拉列表。

$("#season").autocomplete({
   source: function(request, response){
      $.getJSON("search.asp", {
         term: request.term,
         type: 'season'
      }, response);
   },
   minLength: 0,
   select: function(){
      $(this).autocomplete('close');
   }
}).focus(function(event, ui){
   $(this).autocomplete("search", "");
});

熟悉这些文档会产生奇迹:)

http://jqueryui.com/demos/autocomplete/

示例下面的选项卡(选项、事件、方法等)将为您提供您需要了解的所有信息。

编辑:

试试这个,对我有用,但我只在 Chrome、FF3 和 IE8 中进行了测试。

$("#season").autocomplete({
   source: function(request, response){
      $.getJSON("search.asp", {
         term: request.term,
         type: 'season'
      }, response);
   },
   minLength: 0,
   select: function(){
      $('#season').autocomplete('close').blur();
   }
}).click(function(event, ui){
   $(this).autocomplete("search", "");
});

通常,使用点击而不是焦点并不是一个好主意。

Autocomplete has a select event, which is triggered when you select something from the dropdown list. In that event you can call .autocomplete('close') on your input to close the dropdown.

$("#season").autocomplete({
   source: function(request, response){
      $.getJSON("search.asp", {
         term: request.term,
         type: 'season'
      }, response);
   },
   minLength: 0,
   select: function(){
      $(this).autocomplete('close');
   }
}).focus(function(event, ui){
   $(this).autocomplete("search", "");
});

Familiarizing yourself with the docs does wonders :)

http://jqueryui.com/demos/autocomplete/

The tabs below the example (options, events, methods, etc.), will give you all you need to know.

EDIT:

Try this, works for me but I only tested in Chrome, FF3 and IE8.

$("#season").autocomplete({
   source: function(request, response){
      $.getJSON("search.asp", {
         term: request.term,
         type: 'season'
      }, response);
   },
   minLength: 0,
   select: function(){
      $('#season').autocomplete('close').blur();
   }
}).click(function(event, ui){
   $(this).autocomplete("search", "");
});

Typically, using click instead of focus isn't a great idea.

梦途 2024-11-16 09:52:59

为我找到了解决方案。你必须触发模糊并关闭“变化”。

 $("#season").autocomplete({  
            source: function( request, response ) {
                    $.getJSON( "search.asp", {
                        term: request.term,
                        type: 'season'
                        }, response );},
            minLength: 0,
            change: function (event, ui) {
              $(this).autocomplete('close').blur();
            }
        }).focus(function(event, ui){
            $(this).autocomplete("search","");
        });

Found the solution for me. You have to trigger the blur and close on the "change".

 $("#season").autocomplete({  
            source: function( request, response ) {
                    $.getJSON( "search.asp", {
                        term: request.term,
                        type: 'season'
                        }, response );},
            minLength: 0,
            change: function (event, ui) {
              $(this).autocomplete('close').blur();
            }
        }).focus(function(event, ui){
            $(this).autocomplete("search","");
        });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文