JavaScript 实现表单的隔行换色代码

<script type="text/javascript">

 window.onload = function() {
 
  var myTable = document.getElementById("myTable");
  var myTBody = myTable.getElementsByTagName("tbody")[0];
  var myTR = myTBody.getElementsByTagName("tr");
  
  alert("总共  " + myTR.length + " 条记录");
  
  for ( var i = 0; i < myTR.length; i++) {
   if (i % 2 == 0) {
    myTR[i].style.background = "red";
   } else {
    myTR[i].style.background = "green";
   }
  }
 }
</script>

你可能感兴趣的:(JavaScript)