主要代碼如下:
<script type="text/javascript"><!--<br /> function addLabelCol(){<br /> var r = document.getElementById("labelsample");<br /> var r0= r;<br /> var t = _p(event.srcElement,"table");<br /> var r1=t.insertRow(t.rows.length-1);<br />r1.mergeAttributes(r0);<br />for(var i=0,c=r0.cells;i<c.length;i++){<br /> var x=r1.insertCell();<br /> x.innerHTML=c[i].innerHTML;<br /> x.mergeAttributes(c[i]);<br />}<br />}</p><p>function _p(obj,tagName){<br />tagName=tagName.toUpperCase();<br />while(obj.tagName!=tagName)<br /> obj=obj.parentElement;<br />return obj;<br />}<br />function _e(tr,tagName,name){<br /> for(var i=0,c=_t(tr,tagName);i<c.length;i++)<br /> if(c[i].name==name&&c[i].style.display!="none")<br /> return c[i];<br /> return null;<br />}<br /> function _t(obj,tagName){<br /> return obj.getElementsByTagName(tagName);<br /> }</p><p>function removeLabelCol(){<br /> var a=[],b=[],t=_p(event.srcElement,"table");<br /> var size=t.rows.length;<br /> var c = document.getElementsByName("labelFlag");<br /> var num =0;<br /> for(var m=0;m<c.length -1;m++)<br /> if(c[m].checked)<br /> num ++;<br /> if(num<=0) {<br /> alert('Please choose which you want to delete!');<br /> return false ;<br /> } else {<br /> delLabelCol();<br /> }<br />} </p><p>function delLabelCol(){<br />var a=[],t=document.getElementById("labeltable");<br />for(var i=0,c=document.getElementsByName("labelFlag");i<c.length-1;i++){<br /> if(c[i].checked){<br /> a.push(i);<br /> }<br />}<br />while(a.length && t.rows.length>2) {<br /> t.deleteRow(a.pop());<br />}<br />} </p><p>// --></mce:script><br /> <body><br /> <form ><br /> <table id="labeltable" name="labeltable" border="1" width="100%" ><br /> <tr align="left" height="20"><br /> <td><input type="checkbox" name="labelFlag" value="" ></td><br /> <td>Name</td><br /> <td>Auth</td><br /> <td>Price</td><br /> </tr><br /> <tr align="left" height="20"><br /><td><input type="checkbox" name="labelFlag" id="labelFlag" value="" ></td><br /><td>精通Ajax寶典</td><br /><td>李剛</td><br /><td>89</td><br /> </tr><br /> <tr align="left"><br /> <td colspan="4"><br /> <input type="button" id="button" value ="AddOne" onclick="addLabelCol();"><br /> <input onclick="removeLabelCol();" type="button" value="Delete" name="delButton" id="delButton"><br /> </td><br /> </tr><br /> </table><br /> </form><br /><table style="display:none" mce_style="display:none" ><br /> <tr id="labelsample"><br /> <td><input type="checkbox" name="labelFlag" value="" ></td><br /> <td><input type="text" name="name" ></td><br /> <td><input type="text" name="auth" ></td><br /> <td><input type="text" name="price" ></td><br /> </tr><br /> </table><br /> </body>