// 只针对最后一次输入触发
<button id="btn">按钮</button>
<script>
var timer
var btn=document.getElementById("btn");
btn.onclick=function(){
debounce(()=>{
console.log(1)
},1000)
}
function debounce(fn,time){
if(timer){
clearTimeout(timer)
}
timer=setTimeout(fn,time)
}
</script>