<div class="codetitle"> <span><a style="CURSOR: pointer" data="31957" class="copybut" id="copybut31957" onclick="doCopy('code31957')"><u>复制代码</u></a></span>代码如下:</div> <div class="codebody" id="code31957"> <br><html><br> <head><br> < ;meta http-equiv="Content-Type" content="text/html; charset=gb2312"><br> <title>JavaScript</title><br> </head><br> <body> ;<BR> <script language="javascript"><br> var n = 0;<br> function showTable(len) {<br> wi('<table border="1" width="300" style="border-collapse:collapse"><tbody id="table">');<br> for (i=0;i<len;i ) {<BR> if (parseInt(i%2) )==1) {<BR> bg = '#F4FAC7';<BR> } else {<BR> bg = '白'; <BR> }<BR> wi('<tr bgcolor=' bg '><td>第' (i 1) '行</td></tr>'); <br> }<br> wi('</tbody></table><br />');<br> wi('<input type="button" value="Add" id= "追加" />'); <BR> }<BR> function wi(str) {<BR> return document.write(str); <BR> }<BR> showTable(10);<BR> var add = document.getElementById("add");<BR> add.onclick = function() {<BR> n = n 1;<BR> if (n%2==0) {<BR> bg = '#F4FAC7';<BR> } else {<BR> bg = '白'; <BR> }<BR> var table = document.getElementById("table");<BR> var tr = document.createElement("tr");<BR> tr.bgColor = bg;<BR> var td = document .createElement("td");<BR> td.innerHTML = '第' (10 n) '行';<BR> tr.appendChild(td);<BR> table.appendChild(tr);<BR> } <BR> </script><br> </body><br></html> <br> </div>