一、效果

1





2





3





4





二、js代码

<script>
    window.onload=function() {
                      var tbl = document.getElementById("id"); // 先获取table id
                     var rows = tbl.getElementsByTagName("tr"); // 获取里面的行tr
                     for(i=0;i<rows.length;i++) {  // 遍历里面的行
                                 var j = parseInt(i/1); // 以每1行为单位
                            if(j%2==0){ // 再通过取模来设置每隔1行显示不同的两种颜色
                                  rows[i].style.backgroundColor="rgb(255, 255, 255)";
                                   }else{
                                       rows[i].style.backgroundColor="#0f0";
                                 }
                        }
               };
</script>