执行规定一段时间后执行 <input type="text" id="inp" />
<script>
var oInp = document.getElementById("inp")
var timer = null;
function ajax(e) { // 需要执行的函数
console.log(this.value);
}
oInp.oninput = function() {
clearTimeout(timer); // 结束上一次的定时器
var that = this
timer = setTimeout(function() { // 1000ms后执行定时器内的事件
ajax.apply(that, arguments) // 使用apply将this指向到该函数内
}, 1000)
}
</script>