<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<input type="text" id="input">
<script>
var timer=null
document.getElementById("input").addEventListener("keyup",function(){
console.log(this.value)
if(!timer){
clearTimeout(timer),
timer=setTimeout(()=>{ //使用箭头函数 如果是function this获取的是Windows的对象 而不是 input的对象
console.log(this.value,'111111')
},1000)
}
},false)//false 默认冒泡 true 默认捕获
</script>
</body>
</html>
网友评论