小练习 oooo
<script>
var arr = [];
var num = 3;
arr[2] = num;
arr[1] = num - 1;
arr[0] = num - 2;
arr[3] = num + 1;
arr[4] = num + 2;
// console.log(arr);
for (var s of arr) {
var i = document.createElement("i");
i.innerHTML = s;
document.body.appendChild(i);
}
var is = document.querySelectorAll("i");
for (var j = 0; j < arr.length; j++) {
is[j].index = j;
is[j].onclick = function(){
if (arr[this.index] >= 3 ) {
num = arr[this.index];
arr[2] = num;
arr[1] = num - 1;
arr[0] = num - 2;
arr[3] = num + 1;
arr[4] = num + 2;
is = document.querySelectorAll("i");
for(var s = 0;s<is.length;s++){
is[s].innerHTML=arr[s];
}
}
}
}
</script>