Dowemo
0 0 0 0

<title>无标题文档</title><scripttype="text/javascript">functionopendemo(page){ window.open(page,"_blank","");
}</script><styletype="text/css">table, tableth{
 border:#00F1px solid;
 width:600px;}tableth{
 padding:10px;
 }</style></head><body><table><tr><th><inputtype="button"value="演示展开闭合效果"onclick="opendemo('js-1.html')"/></th><th><inputtype="button"value=""onclick="opendemo()"/></th><th><inputtype="button"value=""onclick="opendemo()"/></th></tr><tr><th><inputtype="button"value=""onclick="opendemo()"/></th><th><inputtype="button"value=""onclick="opendemo()"/></th><th><inputtype="button"value=""onclick="opendemo()"/></th></tr><tr><th><inputtype="button"value=""onclick="opendemo()"/></th><th><inputtype="button"value=""onclick="opendemo()"/></th><th><inputtype="button"value=""onclick="opendemo()"/></th></tr></table></body>

There's no way to delete a column directly by deleting the element ( cell ) cell from each row.

<scripttype="text/javascript"src="doctool.js"></script><linkrel="stylesheet"href="css-05.css"/><scripttype="text/javascript">functioncreatTab(){var tabNode= doc.createElement("table");
 var tbdNode = doc.createElement("tboday");
 //alert(tbdNode.nodeName);var trNode= doc.createElement("tr");
 var tdNode = doc.createElement("td");
 var textNode = doc.createElement("单元格一");
 tdNode.appendChild(textNode);
 trNode.appendChild(tdNode);
 tbdNode.appendChild(trNode);
 tabNode.appendChild(tbdNode);
 byTag("div")[0].appendChild(tabNode);
}functioncreateTab2(){var tabNode= doc.createElement("table");
 //tabNode.id="tabid"; tabNode.setAttribute("id","tabid");
 var row = byName("rownum")[0].value;
 var col = byName("colnum")[0].value;
 for(var x = 1; x<=row;x++)
 {
 var trNode = tabNode.insertRow();
 for (var y= 1;y<=col;y++)
 {
 var tdNode = trNode.insertCell(); 
 tdNode.innerHTML=x+"..."+y;
 } 
 }
 //alert(tdNode.nodeName);//tdNode.innerHTML="单元格一".fontcolor("red");//表示添加的是html文本 用text标签不会被解析//tdNode.innerHTML="<input type='button' value='hehe'/>"; byTag("div")[0].appendChild(tabNode);
 event.srcElement.disabled=true; 
}functiondelrow(){var tabNode=byId("tabid");
 if(tabNode==null)
 {
 alert("表格不存在");
 return; 
 }
 var rownum = byName("delrow")[0].value;
 if(rownum>0 &&rownum<=tabNode.rows.length)
 tabNode.deleteRow(rownum-1);
 else {
 alert("删除的行不存在");
 }
}functiondelcol(){var tabNode=byId("tabid");
 if(tabNode==null)
 {
 alert("表格不存在");
 return; 
 }
 var colnum = byName("delcol")[0].value;
 if(colnum>0 &&colnum<=tabNode.rows[0].cells.length)
 {
 for(var x=0;x<tabNode.rows.length;x++)
 {
 tabNode.rows[x].deleteCell(colnum-1); 
 }
 }
 else {
 alert("删除的列不存在"); 
 }
}</script></head><body><!--
通过页面的按钮可以动态的创建一个表格
 --><inputtype="text"name="rownum"/><br/><inputtype="text"name="colnum"/><br/><inputtype="button"value="创建表格"onclick="creatTab()"/><br/><inputtype="text"name="delrow"/><inputtype="button"value="删除行"onclick="delrow()"/><br/><inputtype="text"name="delcol"/><inputtype="button"value="删除列"onclick="delcol()"/><br/><inputtype="button"value="创建表格2"onclick="createTab2()"/><div></div></body>

doctool

//JavaScript Documentvar doc = document;functionbyId(id){return doc.getElementById(id);
}functionbyTag(tag){return doc.getElementsByTagName(tag);
}functionbyName(name){return doc.getElementsByName(name);
}



Copyright © 2011 Dowemo All rights reserved.    Creative Commons   AboutUs