<input type="text" id='demo'/>
<span id='show'></span>
<br>
<input type="text" id='demo2'/>
<span id='show2'></span>
<script>
function debounce (func, delay) {
var timer;
return function () {
var context = this, args = arguments;
clearTimeout(timer);
timer = setTimeout(function () {
func.apply(context, args);
}, delay);
}
}
function update (e) {
show.innerText = this.value;
}
function update2 () {
show2.innerText = this.value;
}
demo.oninput = debounce(update, 300);
demo2.oninput = debounce(update2, 600);
setTimeout定时器写的防抖动
最新推荐文章于 2024-03-08 17:14:19 发布