我想通过一个按钮在一个表格里添加一行一列 并在该列添加一个新按钮

解决方案 »

  1.   

    <table border="1" id="tb1"></table>
    function addRow()
    {
    var tbody = document.getElementById('tb1');
    var NewRow = tbody.insertRow(0);
    var NewCell = NewRow.insertCell(0);
    NewCell.setAttribute("width", "180");
    NewCell.setAttribute("align", "left");
    NewCell.innerHTML = '<input type="button"  id="gg" value="我是按钮"/>';
    }
      

  2.   


    <!doctype html> 
      <html> 
      <head> 
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
      <title>test</title> 
      </head>
      <body>
      <button id="btn">click</button>
      <table id="abc" border="1">
    <tr><td>内容</td><td>按钮</td></tr>
      </table>
      <script type="text/javascript"> 
      window.onload = function(){
    document.getElementById("btn").onclick=function(){
    var tb = document.getElementById("abc");
    var tbody = tb.tBodies[0];
    var tr = tbody.insertRow(tbody.rows.length);
    var td = tr.insertCell(0);
    td.innerHTML = 'hello';
    td = tr.insertCell(1);
    var btn = document.createElement("button");
    btn.innerHTML = "ok";
    td.appendChild(btn);
    }  
      }
      </script>
      
      </body> 
      </html>
      

  3.   

    function addRow()
    {
        var tbody = document.getElementById('tb1');
        var NewRow = tbody.insertRow(0);
        var NewCell = NewRow.insertCell(0);
        NewCell.setAttribute("width", "180");
        NewCell.setAttribute("align", "left");
        NewCell.innerHTML = '<input type="button"  id="gg" value="我是按钮"/>';
    }
      

  4.   

    一行好办,addrow就可以,一列就比较麻烦要循环每一行addcell