js 增加删除表格的行

 function delThisRow(obj,rowNum)  
   {
     var ifNum = num + 1;
     //alert("num="+num);
     //alert("rowNum="+rowNum);
     if(ifNum!=rowNum)
     {
      alert("请先删除最后一行!");
      return;
     }
     num--;
     var table1 = document.getElementById("firstTB");
     table1.firstChild.removeChild(obj.parentNode.parentNode);
   }

 

 

$(document).ready(function(){
        $("#addCheckListType").click(function(){
        num++;
        var str =  '<tr id="first">'
     + '   <td style= "width:20%;text-align:center;">'
     + '  <label/>SECTION'+ (num+1) +'</label>    '
     + '  <input type="hidden" name="UP_CHECKLIST_SECTION_CODE" id="UP_CHECKLIST_SECTION_CODE" value="SECTION'+ (num+1) +'"/>'
     + ' </td>              '
     + ' <td style= "width:20%;text-align:center;">    '
     + '  <input name="UP_CHECKLIST_SECTION_NAME" id="UP_CHECKLIST_SECTION_NAME" type="text" value="" size="10"/> '
     + ' </td>     '
     + ' <td style= "width:20%;text-align:center;"> '
     + '  <input name="UP_CHECKLIST_SECTION_SORTNO" id="UP_CHECKLIST_SECTION_SORTNO" type="text" required label="排序号" error="不能为空,且必须是数字" rule="number" value="" size="10"/> '
     + ' </td> '
     + ' <td style= "width:10%;text-align:center;"> '
     + '  <img src="<%=path%>/includes/images/remove.png" width="16" height="16"  onclick="delThisRow(this,'+(num+1)+');"/> '
     + ' </td> '
     + ' </tr>';
  //alert(str);  
  $("#firstTB").append(str);
    });
   
}); 

 

 

<div style="align:center;width:100%;margin-top:20px;" >
     <tr >
      <td colspan="1" style="text-align:center;"><font style="color:#6fade1;font-size:120%;">&nbsp;&nbsp;章&nbsp;&nbsp;节&nbsp;&nbsp;项:</font></td>
      <td ><img src="<%=path%>/includes/images/add.png" width="16" height="16" id="addCheckListType" /></td>
     </tr>
    </div>
    <table id="firstTB"  style="align:center;width:100%;margin-top:20px;" >
     <tr>
      <td style= "width:20%;text-align:center;">
       章节编号
      </td>
      <td style= "width:20%;text-align:center;">
       章节名称
      </td>
      <td style= "width:20%;text-align:center;">
       排序号
      </td>
      <td style= "width:20%;text-align:center;">
       操作
      </td>
     </tr>
     <%
      if(v_rs!=null && v_rs.size()>0)
      {
       for(int i=0; i<v_rs.size(); i++)
       {
       Record v_rs_rd = v_rs.get(i);
     %>
      <tr>
         <td style= "width:20%;text-align:center;">
        <label/><%=v_rs_rd.getString("CHECKLIST_SECTION_CODE","") %></label>
        <input type="hidden" name="UP_CHECKLIST_SECTION_CODE" id="UP_CHECKLIST_SECTION_CODE" value="<%=v_rs_rd.getString("CHECKLIST_SECTION_CODE","") %>"/>
       </td>
       <td style= "width:20%;text-align:center;">
        <input name="UP_CHECKLIST_SECTION_NAME" id="UP_CHECKLIST_SECTION_NAME" type="text" value="<%=v_rs_rd.getString("CHECKLIST_SECTION_NAME","") %>" size="10"/>
       </td>
       <td style= "width:20%;text-align:center;">
        <input name="UP_CHECKLIST_SECTION_SORTNO" id="UP_CHECKLIST_SECTION_SORTNO" type="text" required label="排序号" error="不能为空,且必须是数字" rule="number" value="<%=v_rs_rd.getString("CHECKLIST_SECTION_SORTNO","") %>" size="10"/>
       </td>
       <td style= "width:10%;text-align:center;">
        <img src="<%=path%>/includes/images/remove.png" width="16" height="16" onclick="delThisRow(this,'<%=i+1 %>');" />
       </td>
      </tr>
     <%
       }
      }else{
     %>
      <tr>
         <td style= "width:20%;text-align:center;">
        <label/>SECTION1</label>
        <input type="hidden" name="UP_CHECKLIST_SECTION_CODE" id="UP_CHECKLIST_SECTION_CODE" value="SECTION1"/>
       </td>
       <td style= "width:20%;text-align:center;">
        <input name="UP_CHECKLIST_SECTION_NAME" id="UP_CHECKLIST_SECTION_NAME" type="text" value="" size="10"/>
       </td>
       <td style= "width:20%;text-align:center;">
        <input name="UP_CHECKLIST_SECTION_SORTNO" id="UP_CHECKLIST_SECTION_SORTNO" type="text" required label="排序号" error="不能为空,且必须是数字" rule="number" value="" size="10"/>
       </td>
       <td style= "width:10%;text-align:center;">
        <img src="<%=path%>/includes/images/remove.png" width="16" height="16" onclick="delThisRow(this,1);" />
       </td>
      </tr>
      <%
       }
       %>
    </table>

posted @ 2012-06-20 16:47  Brook Legend  阅读(146)  评论(0)    收藏  举报