// 只针对最后一次输入触发

    1. <button id="btn">按钮</button>
    2. <script>
    3. var timer
    4. var btn=document.getElementById("btn");
    5. btn.onclick=function(){
    6. debounce(()=>{
    7. console.log(1)
    8. },1000)
    9. }
    10. function debounce(fn,time){
    11. if(timer){
    12. clearTimeout(timer)
    13. }
    14. timer=setTimeout(fn,time)
    15. }
    16. </script>

    01.gif