JSP動態添加行

來源:互聯網
上載者:User

主要代碼如下:

<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>

 

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.