我离开野外后取消自动完成
-
03-10-2019 - |
题
如果用户离开页面看,有没有办法停止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 );
},
});
解决方案
绑定 blur
该场地的活动处理程序(本质上是一个丢失的焦点事件):
$("#request_song").blur(function(){
// Using disable and close after destroy is redundant; just use destroy
$(this).autocomplete("destroy");
});
不隶属于 StackOverflow