日期:2014-05-16  浏览次数:20470 次

jsp页面实现行的增加,删除
   <%@ page contentType="text/html; charset=GBK" %>
   <html> 
   <head> 
   <script type="text/javascript"> 
   function deleteRow(r) 
   { 
   var i=r.parentNode.parentNode.rowIndex 
   document.getElementById('myTable').deleteRow(i) 
   } 
    
   function insertRowInTable(){ 
   var table = document.getElementById("myTable"); 
   var newRow = table.insertRow(-1); 
   newRow.insertCell().innerHTML = "Row " +(newRow.rowIndex+1); 
   newRow.insertCell(-1).innerHTML = "<input type='button' value='删除' onclick='deleteRow(this)'>"; 
   } 
   </script> 
   </head> 
   <body> 
    
   <table id="myTable" border="1"> 
   <tr> 
   <td>Row 1</td> 
   <td><input type="button" value="删除" onclick="deleteRow(this)"></td> 
   </tr> 
   <tr> 
   <td>Row 2</td> 
   <td><input type="button" value="删除" onclick="deleteRow(this)"></td> 
   </tr> 
   <tr> 
   <td>Row 3</td> 
   <td><input type="button" value="删除" onclick="deleteRow(this)"></td> 
   </tr> 
   </table> 
   <input type="button" onclick="insertRowInTable();" value="插入一行" /> 
   </body> 
   </html>