定时器
防抖动(debounce)
$('textarea').on('keydown', debounce(ajaxAction, 2500));
function debounce(fn, delay){
var timer = null; // 声明计时器
return function() {
var context = this;
var args = arguments;
clearTimeout(timer);//清空timer计时器
timer = setTimeout(function () {
fn.apply(context, args);
}, delay);
};
}节流
Last updated