<div class="htmlarea"> <textarea id="runcode71976"> <title>양식 개체 예시</title> <form name="ylform" id="ylform"> <center> <input name="button" type="button" onclick="inserttable()" value="增加表格"> <input name="button2" type="button" onclick="insertrow1()" value="增加一行1"> <input name="button22" type="button" onclick="insertrow2()" value="增加一行2"> </center> <table border="1" align="center" width="50%" id="yltable"> <tbody id="yl1"> <tr> <td width="30%" height="22"><div align="center">1</div></td> <td width="40%"> <div align="center"> <input name="textfield" type="text" value="yl"> </div> </td> <td width="30%"><div align="center"> <input name="button3" type="button" onclick="delrow1()" value="删除1"> <input name="button3" type="button" onclick="delrow2()" value="删除2"> </div></td> </tr> </tbody> <tbody id="yl2"> <tr> <td><div align="center">2</div></td> <td><div align="center"> <input name="textfield2" type="text" value="yanleigis"> </div></td> <td><div align="center"> <input name="button3" type="button" onclick="delrow1()" value="删除1"> <input name="button3" type="button" onclick="delrow2()" value="删除2"> </div></td> </tr> </tbody> <tbody id="yl3"> <tr> <td><div align="center">3</div></td> <td><div align="center"> <input name="textfield22" type="text" value="Landgis@126.com"> </div></td> <td><div align="center"> <input name="button3" type="button" onclick="delrow1()" value="删除1"> <input name="button3" type="button" onclick="delrow2()" value="删除2"> </div></td> </tr> </tbody> </table> <center> </center> </form> </textarea> <br><input onclick="runEx('runcode71976')" type="button" value="运行代码"><input onclick="doCopy('runcode71976')" type="button" value="复制代码"> <input onclick="doSave(runcode71976)" type="button" value="保存代码"> <a href="http://www.jb51.net/article/23421.htm" title="查看具体详情" target="_blank">[Ctrl A 모두 선택 참고: </a>외부 J를 도입해야 하는 경우 실행하려면 새로 고쳐야 합니다 </div>]<script language="javascript"> function delrow1() { var oElement=event.srcElement; while(oElement.tagName!="TR") { oElement=oElement.parentElement; } var oTBody=oElement.parentElement; oTBody.removeChild(oElement) } function delrow2()//刪除当前行 { var currRowIndex=event.srcElement.parentNode.parentNode.rowIndex; document.all.yltable.deleteRow(currRowIndex);//table10--表格id } function insertrow1() //增加的一行方法1 { var newnode = document.getElementById('yltable').lastChild.cloneNode(true); document.getElementById('yltable').appendChild(newnode); } function insertrow2() //增加的一行方法2 { newRow=document.all.yltable.insertRow(-1); var j_1 = document.all.yltable.rows.length; newcell=newRow.insertCell(); newRow.bgColor='#FFFFFF'; newcell.align='center'; newcell.innerHTML=""+j_1+""; newcell=newRow.insertCell() ; newRow.bgColor='#FFFFFF'; newcell.align='center'; newcell.innerHTML="<input type='text' name='ylText"+j_1+"' />"; newcell=newRow.insertCell() ; newRow.bgColor='#FFFFFF'; newcell.align='center'; newcell.innerHTML='<input name="button3" type="button" onClick="delrow1()" value="删除1"> <input name="button3" type="button" onClick="delrow2()" value="删除2">'; document.all.yltable.focus(); } function inserttable() { var newnode = document.getElementById('yltable').cloneNode(true); document.getElementById('ylform').appendChild(newnode); } </script>