独立计数器

<body>
  <input type="button" value="0"/>
  <input type="button" value="0"/>
  <input type="button" value="0"/>
  <script>
  var aBtn = document.getElementsByTagName("input");
  var arr = ["A","B","C","D"];
  /*for(var i=0;i<aBtn.length;i++){
  aBtn[i].onclick = function (){
  this.value++;
  //this.value += 1
  //this.value = this.value + 1
  }
  }*/
  for(var i=0;i<aBtn.length;i++){
  aBtn[i].j = 0;
  aBtn[i].onclick = function (){
  this.value = arr[this.j++%4];
  }
  }
  </script>
  </body>

猜你喜欢

转载自blog.csdn.net/cosmos033/article/details/80397124