problem description
I want to do loop detection on keys several times, such as using for loop to detect buttons three times, and each time I detect that the button is triggered, I will execute the specified function, such as I press the space (keyCode=32), then print 1 in the background, and press three times to print out three 1s.
but the problem I have now is that three 1s will pop up once, with the code as follows:
<html>
<script type="text/javascript">
for(let i=0;i<3;iPP){
document.addEventListener("keydown",function(){
var e = event || window.event || arguments.callee.caller.arguments[0];
if(e.keyCode!=null&&e.keyCode==32){
console.log("ok");
}
})
}
</script>
</html>
ask the boss to answer questions ~