1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
// 进行节流操作 function ajax(content) { console.log('ajax request ' + content) }
function debounce(fun, delay) { return function (args) { let that = this let _args = args clearTimeout(fun.id) fun.id = setTimeout(function () { fun.call(that, _args) }, delay) } }
let inputb = document.getElementById('testa')
let debounceAjax = debounce(ajax, 500)
inputb.addEventListener('keyup', function (e) { debounceAjax(e.target.value) })
|
近期评论