<html>
<head>
<script>
function deleteTable() {
var oParent = document.getElementById("tb1").parentNode;
oParent.removeChild(document.getElementById("tb1"));
}
</script>
</head>
<body>
 <table id="tb1" style="border:1px solid blue;">
  <tr>
   <td>hello1<td/><td>hello2<td/><td>hello3<td/>
  <tr/>
  <tr>
   <td>hello1<td/><td>hello2<td/><td>hello3<td/>
  <tr/>
  <tr>
   <td>hello1<td/><td>hello2<td/><td>hello3<td/>
  <tr/>
  <tr>
   <td>hello1<td/><td>hello2<td/><td>hello3<td/>
  <tr/>
 </table>
</body>
 </table>  <input type="button" value="delete" onclick="deleteTable()"/>
</html>

解决方案 »

  1.   


    <html>
        <head>
            <script>
                function deleteTable() {
                    var oParent = document.getElementById("tb1").parentNode; //获取table的父结点
                    oParent.removeChild(document.getElementById("tb1")); //从table的父结点中删除table子结点
                }
            </script>
        </head>
        <body>
             <table id="tb1" style="border:1px solid blue;">
                  <tr>
                   <td>hello1<td/><td>hello2<td/><td>hello3<td/>
                  <tr/>
                  <tr>
                   <td>hello1<td/><td>hello2<td/><td>hello3<td/>
                  <tr/>
                  <tr>
                   <td>hello1<td/><td>hello2<td/><td>hello3<td/>
                  <tr/>
                  <tr>
                   <td>hello1<td/><td>hello2<td/><td>hello3<td/>
                  <tr/>
             </table>
        </body>
     </table>  <input type="button" value="delete" onclick="deleteTable()"/>
    </html>加点注释 :-)
      

  2.   

    <div id=tbl>
    <table>
    .....
    </table>
    </div>
    <input type=button value="删除表格" onclick="document.getElementById('tbl').innerHTML='';">如果不要占位的话,onclick后面改为onclick="var o=document.getElementById('tbl');o.innerHTML='';o.style.display='none'"
      

  3.   

    谢谢了,可是谁能告诉我,怎么能把那个del按钮也删除了呢?
      

  4.   


    <input type="button" value="delete" onclick="this.parentNode.removeChild(this);">
      

  5.   

    其实只要找到你想要删除的对象 obj.
    然后 obj.parentNode.removeChild(this);
      

  6.   

    唉! 我又写错了.
    看来以后不能再上论坛了.obj.parentNode.removeChild(obj);
      

  7.   

    哈,LZ兄弟搞脑筋急转弯吧:))你把8楼代码中的按钮放到div里面去不就没了吗?呵呵