<button class="btn">aa</button>
<script>
var aBtn=document.getElementsByClassName('btn');
var i = 0;
while(i<aBtn.length){
aBtn[i].onclick = function(){
console.log(i);
// 1 ??????
}
i++
}
</script>
I'd like to know why the console outcome is 1 in the end, instead of 0.