核心提示:输入内容后延迟1秒发送请求input type=text id=input /scriptvar input = document.getElementById(input);function deb...
输入内容后延迟1秒发送请求
<input type="text" id="input" />
<script>
var input = document.getElementById('input');
function debounce(handler, delay) {
var timer = null;
return function () {
var _salf = this,
_arg = arguments;
clearTimeout(timer);
timer = setInterval(function () {
handler.apply(_salf, _arg);
}, delay);
}
}
function ajax() {
console.log(this.value);
}
input.oninput = debounce(ajax, 1000);
</script>


