可不可以把里面的tr弄个统一的id呢

解决方案 »

  1.   

    <!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>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    </head><body>
    <table width="200" border="1">
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td><input type="button" name="cancle" value="取消" onclick="this.parentNode.parentNode.parentNode.deleteRow(this.parentNode.parentNode.rowIndex)"/></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
    </table>
    </body>
    </html>
      

  2.   


    <SCRIPT LANGUAGE="JScript">
    var n = null;
    function doit(obj){
    var td = obj.parentNode.parentNode;
    td.removeNode(true);
    }
    </SCRIPT><table>
    <tr><td>1xxxx</td><td><input type="button" value="取消" onclick="doit(this);"></td></tr>
    <tr><td>2xxxx</td><td><input type="button" value="取消" onclick="doit(this);"></td></tr>
    <tr><td>3xxxx</td><td><input type="button" value="取消" onclick="doit(this);"></td></tr>
    </table>
      

  3.   


    <table border="1" width="100%" id="table1">
    <tr>
    <td width="25%"> </td>
    <td width="25%"> </td>
    <td width="25%"> </td>
    <td width="25%"><input type=button value="取消" onclick="delrow(this);"></td>
    </tr>
    <tr>
    <td> </td>
    <td> </td>
    <td> </td>
    <td><input type=button value="取消" onclick="delrow(this);"></td>
    </tr>
    <tr>
    <td> </td>
    <td> </td>
    <td> </td>
    <td><input type=button value="取消" onclick="delrow(this);"></td>
    </tr>
    </table>
    <script language=javascript>
    function delrow(o)
    {
    o.parentNode.parentNode.removeNode(true);
    }
    </script>
    IE测试过,其他浏览起没测试
      

  4.   

    优化一下象这样:
    <!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>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    <script>
    function delrow(o){
    table = o.parentNode.parentNode.parentNode
    tr = o.parentNode.parentNode
    table.deleteRow(tr.rowIndex)
    }
    </script>
    </head><body>
    <table width="200" border="1">
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td><input type="button" name="cancle" value="取消" onclick="delrow(this)"/></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td><input type="button" name="cancle" value="取消" onclick="delrow(this)"/></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td><input type="button" name="cancle" value="取消" onclick="delrow(this)"/></td>
      </tr>
    </table>
    </body>
    </html>
      

  5.   

    removeNode只是ie可以.
    deleteRow和rowIndex是标准的.
    测试通过.
      

  6.   

    <!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>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title></head><body>
    <div style="width:600px" align="center">
    <table id="tb" width="200" border="1" align="left">
      <tr>
        <td>1</td>
        <td>&nbsp;</td>
        <td>      <input type="button" name="button" onclick="del(this)" id="button" value="取消" /></td>
      </tr>
      <tr>
        <td>2</td>
        <td>&nbsp;</td>
        <td>      <input type="button" name="button" onclick="del(this)" id="button" value="取消" /></td>
      </tr>
      <tr>
        <td>3</td>
        <td>&nbsp;</td>
        <td>      <input type="button" name="button" onclick="del(this)" id="button" value="取消" /></td>
      </tr>
      <tr>
        <td>4</td>
        <td>&nbsp;</td>
        <td>      <input type="button" name="button" onclick="del(this)" id="button" value="取消" /></td>
      </tr>
      <tr>
        <td>5</td>
        <td>&nbsp;</td>
        <td>      <input type="button" name="button" onclick="del(this)" id="button" value="取消" /></td>
      </tr>
    </table>
    <script language="javascript">
    function $ (id)
    {
    return document.getElementById(id);
    }

    function del(obj)
    {
    var tb = $("tb"); for(var i=0;i<tb.rows.length;i++)
    {
    if(tb.rows[i] == obj.parentElement.parentElement)
    {
    tb.deleteRow(i);
    return ;
    }
    }
    }
    </script>
    </div>
    </body>
    </html>
      

  7.   


    收藏onclick="this.parentNode.parentNode.parentNode.deleteRow(this.parentNode.parentNode.rowIndex)"
      

  8.   

    搞定,用了myvicy的方法,多谢各位前辈哈~结了~