js函数节流

This commit is contained in:
lizanle 2015-10-19 09:55:19 +08:00
parent f25015c6b8
commit 5652a60c68
1 changed files with 12 additions and 1 deletions

View File

@ -557,6 +557,17 @@
// }); // });
//查询学校 //查询学校
$("input[name='province']").on('input', function (e) { $("input[name='province']").on('input', function (e) {
throttle(shcool_search_fn,window,e);
});
function throttle(method,context,e){
clearTimeout(method.tId);
method.tId=setTimeout(function(){
method.call(context,e);
},500);
}
function shcool_search_fn(e){
$("input[name='occupation']").val(''); //一旦有输入就清空id。 $("input[name='occupation']").val(''); //一旦有输入就清空id。
if($(e.target).val().trim() == lastSearchCondition && $(e.target).val().trim() != ''){ if($(e.target).val().trim() == lastSearchCondition && $(e.target).val().trim() != ''){
return; return;
@ -592,7 +603,7 @@
} }
} }
}); });
}); }
$(document.body).click(function(e){ $(document.body).click(function(e){
if($(e.target).attr("id") != 'search_school_result_list' && $(e.target).attr("id") != 'province') if($(e.target).attr("id") != 'search_school_result_list' && $(e.target).attr("id") != 'province')
{ {