利用Javascript在表格的每一行动态添加了一个input 按钮,并且添加了相应的按钮点击事件
我想点击这个按钮就删除相应的行
我的思路是
实现删除行,Javascript提供了 deleteRow(index) 根据行索引删除行
可是,不知道怎么获取行的索引?请指教。或者,有没有其它方法实现点击按钮实现删除行

解决方案 »

  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=utf-8" />
    <title>无标题文档</title>
    </head><body>
    <table id="tb">
    <tr><td>TEST</td><td><input type="button" onclick="document.getElementById('tb').deleteRow(this.parentNode.parentNode.rowIndex);" value="REMOVE" /></td></tr>
    </table>
    </body>
    </html>
      

  2.   

    写成函数可以这样做:
    <!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>
    <script type="text/javascript">
    function rmRow(t) {
    var idx = t.parentNode.parentNode.rowIndex;
    document.getElementById('tb').deleteRow(idx);
    }
    </script>
    </head><body>
    <table id="tb">
    <tr><td>TEST_ROW1</td><td><input type="button" onclick="rmRow(this);" value="REMOVE" /></td></tr>
    <tr><td>TEST_ROW2</td><td><input type="button" onclick="rmRow(this);" value="REMOVE" /></td></tr>
    </table>
    </body>
    </html>
      

  3.   


    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title></title>
        <script type="text/javascript">
            function deleteSelf(obj) {
                var trobj = obj.parentNode.parentNode;
                trobj.parentNode.removeChild(trobj);
            }
        </script>
    </head>
    <body>
    <table>
        <tr><td>1</td><td><a href="#@" onclick="deleteSelf(this);">删除自己</a></td></tr>
         <tr><td>2</td><td><a href="#@" onclick="deleteSelf(this);">删除自己</a></td></tr>
          <tr><td>3</td><td><a href="#@" onclick="deleteSelf(this);">删除自己</a></td></tr>
    </table>
    </body>
    </html>
      

  4.   

    有谁知道如何禁止拉动浏览器大小?!吗
    http://topic.csdn.net/u/20110418/22/7e5b17a5-e255-417b-8196-3f095064aaf8.html?21601