<%@ Page Language="C#" AutoEventWireup="true" CodeFile="jq Rows.aspx.cs" Inherits="Default2" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
  <title></title>
  <script src="js/jquery-1.3.2.min.js" type="text/javascript"></script>
  <script type="text/javascript">
        $(document).ready(function(){
            $("#but_add").click(function(){
                
               var col = $("#tab").find("tr").eq(1).clone(); 
               col.appendTo("#tab");
            });
            $("#but_del").click(function(){//删除事件
               这里如何写删除行代码  
                 //$("#tab tr:gt(0)").each(function(){ });                  
                           
            });
        });
  </script>
</head>
<body>
  <form id="form1" runat="server">
  
        <table border="0" cellpadding="0" cellspacing="0" id="tab1" align="center"  width="25%" bgcolor="#CCCCCC">
        <tr>
               <td></td>
               <td style="text-align:right"><input type="button" id="but_add" value="添加" />
               <input type="button" id="but_del" value="删除" /></td>
        </tr></table>
        
        <table border="1" cellpadding="2" cellspacing="0" id="tab" align="center"  width="25%">
            <tr>
                <td><input type="checkbox" id="ck" /></td>
                <td style="text-align:center">序号</td>
                <td style="text-align:center">内容</td>
            </tr>
            <tr>
                <td><input type="checkbox" /></td>
                <td><input type="text" value=""/></td>
                <td><input type="text" id="txt_but1" /></td>
            </tr>
        </table>
         </form>
</body>
</html>

解决方案 »

  1.   

    $("#tab tr").remove();   
      

  2.   

    function addRow(){
    $('#tb_commodity').append(
    "<tr><td><input type='text' size='20'/></td><td><button name='btn_add'  onclick='delRow(this)'"+
    " class='bt1_mouseout' onmouseover='this.className=\"bt1_mouseover\"' onmouseout='this.className=\"bt1_mouseout\"'>删除</button></td></tr>");
    }
    function delRow(a){
    alert($(a).get(0));
    $(a).parent().parent().remove();
    }
      

  3.   

    可能是我没说明白 每行前面不是有个checkbox控件么 当删除的时候我需要判断下该行的这个控件是否选中 如果选中则删除该行。否则不删除
      

  4.   

    那你的首先获取那个控件的ID   再判断控件IS Check 的状态
      然后再执行删除的动作
      

  5.   


     function Deletetr() {
                var cbs = $('#tab input:[type="checkbox"]');
                cbs.each(function() {
                    $cb = $(this);
                    if ($cb.attr("checked") == true) 
                        $cb.parent("td").parent("tr").remove();
                });
            }
      

  6.   


    <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>无标题页</title>
        <script src="jquery-1.3.2-vsdoc.js" type="text/javascript"></script>
        <script type="text/javascript">
            $(function() {
                $("#but_del").click(function() {
                    $("input[name='checkbox']:checked").each(function() {                    $(this).parent().parent().remove();
                    })
                });        });    
        </script>
        
    </head>
    <body>
         <form id="form1" name="form1" method="get" runat="server">
         <table border="0" cellpadding="0" cellspacing="0" id="tab1" align="center" width="25%" bgcolor="#CCCCCC">
      <tr>
      <td></td>
      <td style="text-align:right"><input type="button" id="but_add" value="添加" />
      <input type="button" id="but_del" value="删除" /></td>
      </tr></table>
        
      <table border="1" cellpadding="2" cellspacing="0" id="tab" align="center" width="25%">
      <tr>
      <td><input type="checkbox" name="checkbox" /></td>
      <td style="text-align:center">序号</td>
      <td style="text-align:center">内容</td>
      </tr>
      <tr>
      <td><input type="checkbox" name="checkbox" /></td>
      <td><input type="text" value=""/></td>
      <td><input type="text" id="txt_but1" /></td>
      </tr>
      </table>    </form>
    </body>
    </html>
      

  7.   

      $("#tb_MailList")[0].deleteRow(1);
      

  8.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" >
      <title>表单删除</title>
      <script src="js/jquery-1.3.2.min.js" type="text/javascript"></script>
      <script type="text/javascript">
      $(document).ready(function(){
      $("#but_add").click(function(){    
      var col = $("#tab").find("tr").eq(1).clone();  
      col.appendTo("#tab");
      });
      
      $("#but_del").click(function(){//删除事件   
    $("input[type='checkbox']:checked").each(
    function() {
    $(this).parent("td").parent("tr").remove();
    }
    )
      });
      });
      </script>
    </head>
    <body>
    <table border="0" cellpadding="0" cellspacing="0" id="tab1" align="center" width="25%" bgcolor="#CCCCCC">
    <tr>
    <td></td>
    <td style="text-align:right">
    <input type="button" id="but_add" value="添加" />
    <input type="button" id="but_del" value="删除" />
    </td>
    </tr>
    </table>
        
    <table border="1" cellpadding="2" cellspacing="0" id="tab" align="center" width="25%">
    <tr>
    <td>
    <input type="checkbox" id="ck" onlick=""/>
    </td>
    <td style="text-align:center">序号</td>
    <td style="text-align:center">内容</td>
    </tr>
    <tr>
    <td><input type="checkbox" /></td>
    <td><input type="text" value=""/></td>
    <td><input type="text" id="txt_but1" /></td>
    </tr>
    </table>
    </body>
    </html>