JavaScript学习笔记(二)防抖函数
function debounce(func, waite) { let timerId = null return function(...args) { if (timerId) { clearTimeout(timerId) } timerId = setTimeout(() => { func(...args) }, waite) } } let txtChange = debounce(event => { console.log(event.target.value) }, 500) document.getElementById('txt').onkeyup = event => { txtChange(event) }