1. <html>  

  2.     <head>  

  3.         <meta http-equiv="Content-Type" content="text/html; charset=gb2312">  

  4.         <title>JavaScript</title>  

  5.     </head>  

  6.     <body>  

  7.         <script language="javascript">  

  8.             var n = 0;  

  9.             function showTable(len) {  

  10.                 wi('<table border="1" width="300" style="border-collapse:collapse"><tbody id="table">');  

  11.                 for (i=0;i<len;i++) {  

  12.                     if (parseInt(i%2)==1) {  

  13.                         bg = '#F4FAC7';  

  14.                     } else {  

  15.                         bg = 'white';     

  16.                     }  

  17.                     wi('<tr bgcolor='+bg+'><td>第'+(i+1)+'行</td></tr>');   

  18.                 }  

  19.                 wi('</tbody></table><br />');  

  20.                 wi('<input type="button" value="Add" id="add" />');     

  21.             }  

  22.               

  23.             function wi(str) {  

  24.                 return document.write(str);   

  25.             }  

  26.             showTable(10);  

  27.               

  28.             var add = document.getElementById("add");  

  29.             add.onclick = function() {  

  30.                 n = n+1;  

  31.                 if (n%2==0) {  

  32.                     bg = '#F4FAC7';  

  33.                 } else {  

  34.                     bg = 'white';     

  35.                 }  

  36.                 var table = document.getElementById("table");  

  37.                 var tr = document.createElement("tr");  

  38.                 tr.bgColor = bg;  

  39.                 var td = document.createElement("td");  

  40.                 td.innerHTML = '第'+(10+n)+'行';  

  41.                 tr.appendChild(td);  

  42.                 table.appendChild(tr);  

  43.             }  

  44.         </script>  

  45.     </body>  

  46. </html>