<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<input type="text" name="" id="input" value="">
<input type="submit" id="button" />
</body>
<script>
let input = document.getElementById('input')
let button = document.getElementById('button')
button.addEventListener('click', debounce(submit, 1000), false);
function submit(e) {
console.log(e, this)
}
function throttle(fn, delay) {
let begin = 0;
return function () {
let cur = new Date().getTime();
if (cur - begin > delay) {
fn.apply(this, e);//fn函数可以使用click时产生的事件对象
}
begin = cur;
}
}
</script>
</html>