转载自:https://www.cnblogs.com/linxue/p/9330088.html
防抖:可以在停留的时候获取input中的值
function debounce(fn,delay){
let delays=delay||500;
let timer;
return function(){
let th=this;
let args=arguments;
if (timer) {
clearTimeout(timer);
}
timer=setTimeout(function () {
timer=null;
fn.apply(th,args);
}, delays);
};
}
//监听input的输入事件
$('#debounceInput').on('input propertychange',debounce(function(){
$('.print').append('<p>输出值:'+$(this).val()+','+new Date()+'<p>');
console.log($(this).val(),new Date())
}));