<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript">
window.onload=function() {
var tbl = document.getElementById("tbl");
var rows = tbl.getElementsByTagName("tr");
for(i=0;i<rows.length;i++) {
var j = parseInt(i/3); // 此语句的效果是,以3个为单位,000 111 222 333 444 ...
if(j%2==0) rows[i].style.backgroundColor="#f00";
else rows[i].style.backgroundColor="#0f0";
}
};
</script>
</head>
<body>
<table id="tbl" border="1">
<tr><td>1</td></tr>
<tr><td>2</td></tr>
<tr><td>3</td></tr>
<tr><td>4</td></tr>
<tr><td>5</td></tr>
<tr><td>6</td></tr>
<tr><td>7</td></tr>
<tr><td>8</td></tr>
<tr><td>9</td></tr>
<tr><td>10</td></tr>
<tr><td>11</td></tr>
<tr><td>12</td></tr>
<tr><td>13</td></tr>
<tr><td>14</td></tr>
<tr><td>15</td></tr>
<tr><td>16</td></tr>
<tr><td>17</td></tr>
<tr><td>18</td></tr>
</table>
</body>
</html>
05-01 04:25