<div class="codetitle"> <span><a style="CURSOR: pointer" data="98312" class="copybut" id="copybut98312" onclick="doCopy('code98312')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code98312"> <br><br><br><br><meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <br><title>无标题文档</title> <br><link rel="stylesheet" href="tab.css"> <br><script type="text/javascript" src="../Day26/doctool.js"></script><br><script type="text/javascript"><BR>function createTab1()<BR>{<BR> var tabNode = doc.createElement("table");<BR> var tbdNode = doc.createElement("tbody");<BR> var trNode = doc.createElement("tr");<BR> var tdNode = doc.createElement("td");<BR> var textNode = doc.createTextNode("单元格一");<BR> tdNode.appendChild(textNode);<BR> trNode.appendChild(tdNode);<BR> tbdNode.appendChild(trNode);<BR> tabNode.appendChild(tbdNode);<BR> byTag("div")[0].appendChild(tabNode);<BR>}<BR>function createTab()<BR>{<BR> var tabNode = doc.createElement("table");<BR> //tabNode.id = "tabid";<BR> tabNode.setAttribute("id","tabid");<BR> var row = byName("rownum")[0].value;<BR> var col = byName("colnum")[0].value;<BR> for(var x=1; x<=row; x++)<BR> {<BR> var trNode = tabNode.insertRow();<BR> for(var y=1; y<=col; y++)<BR> {<BR> var tdNode = trNode.insertCell();<BR> tdNode.innerHTML = x+"...."+y;<BR> }<BR> }<BR> byTag("div")[0].appendChild(tabNode);<BR> event.srcElement.disabled = true;<BR>}<BR>function delRow()<BR>{<BR> var tabNode = byId("tabid");<BR> if(tabNode==null)<BR> {<BR> alert("表格不存在 ");<BR> return;<BR> }<BR> var rownum = byName("delrow")[0].value;<BR> if(rownum>0 && rownum<=tabNode.rows.length)<BR> tabNode.deleteRow(rownum-1);<BR> else<BR> {<BR> alert("删除的行不存在,学习数数很重要");<BR> }<BR>}<BR>function delCol()<BR>{<BR> var tabNode = byId("tabid");<BR> if(tabNode==null)<BR> {<BR> alert("表格不存在 ");<BR> return;<BR> }<BR> var colnum = byName("delcol")[0].value;<BR> if(colnum>0 && colnum<=tabNode.rows[0].cells.length)<BR> {<BR> for(var x=0;x<tabNode.rows.length; x++)<BR> {<BR> tabNode.rows[x].deleteCell(colnum-1);<BR> }<BR> }<BR> else<BR> {<BR> alert("删除的列不存在");<BR> }<BR>}<BR></script><br><br><br><!--<BR>通过页面的按钮可以动态的创建一个表格。<BR>--><br>行:<input type="text" name="rownum"><br><br>列:<input type="text" name="colnum"><br><br><input type="button" value="创建表格" onclick="createTab()"><br><br><input type="text" name="delrow"><br><input type="button" value="删除行" onclick="delRow()"><br><br><br><input type="text" name="delcol"><br><input type="button" value="删除列" onclick="delCol()"><br><br><br><br><br><div><br></div> <br><br><br> </div>