2

ユーザーがドキュメントを見てページを離れた場合、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 );
  },
});
4

1 に答える 1

6

blurイベント ハンドラーをフィールドにバインドします (基本的には、フォーカスが失われたイベントです)。

$("#request_song").blur(function(){
    // Using disable and close after destroy is redundant; just use destroy
    $(this).autocomplete("destroy");
});
于 2010-09-16T00:36:57.633 に答える