离开现场后取消自动完成

时间:2010-09-16 00:32:34

标签: jquery jquery-ui jquery-ui-autocomplete

如果用户离开页面查看Documentation here我看到很多东西,有没有办法停止ui jQuery自动填充

.autocomplete( "destroy" )
.autocomplete( "disable" )
.autocomplete( "close" )

但是如何在用户离开字段后使用它们

$("#request_song").autocomplete({
  source: function(req, add){
    $.getJSON('<%= ajax_path("trackName") %>', req, function(data) {
      var suggestions = data.suggestions;
      add(suggestions);
    });
  },
  change: function() {
    var main = $('#main_content');
    main.empty().append("<img id=\"throbber\" src='/pre_config/css/images/throbber.gif' alt='Loading. Please wait.' />");
    $("#band_events").load("/load_events/"+ escape($('#request_artist').val()), successCallback );
  },
});

1 个答案:

答案 0 :(得分:6)

blur事件处理程序绑定到字段(本质上是丢失焦点事件):

$("#request_song").blur(function(){
    // Using disable and close after destroy is redundant; just use destroy
    $(this).autocomplete("destroy");
});