日期:2014-05-16  浏览次数:20421 次

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>