页面上点击一个按钮。添加一个TABLE或者TABLE中添加一行,并且TABLE或这行里面有一个TEXTBOX 和一个BUTTON?

解决方案 »

  1.   

    可以用insertRow和insertCell,然后使用innerHtml
    也可以用document.createElement
      

  2.   


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
     <head>
      <title> New Document </title>
      <script type="text/javascript">
    function add(){
    var tb = document.getElementById("tb");
    var tr = tb.insertRow(-1);
    var td = tr.insertCell(-1);
    var text = document.createElement("input");
    text.type="text";
    td.appendChild(text);
    td = tr.insertCell(-1);
    var button = document.createElement("input");
    button.type="button"; button.value="Save";
    td.appendChild(button);
    }
      </script>
     </head> <body>
      <input type="button" value="添加" onclick="add()" />
      <table id="tb">
    <th>text</th><th>button</th>
      </table>
     </body>
    </html>
      

  3.   

    <SCRIPT LANGUAGE="JavaScript">
    function getTD(){
        var obj=document.getElementById("table1");
        if(obj==null){
            obj=document.createElement("table");
            obj.id="table1";
            document.body.appendChild(obj);
        }
        var row=obj.insertRow();
        var cell=row.insertCell();
        cell.innerHTML="<input><input type=button>";
    }
    </SCRIPT>
    <input type=button value=getTD onclick="getTD();">
      

  4.   

    以上两种方法,可以,但是加的是INPUT的控件,可不可以加第三方控件?
    〈ig:WebTextEditor ID='txtLink' runat='server' Width='100%'/>
      

  5.   


    <!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>js测试</title>
    <style>
    </style>
    <script src="jquery-1.3.2.js"></script>
    <script>
    $(document).ready(function(){
        $("#btn").click(function(){
             $("#table").append("<tr>"
    +"<td><input type='button' value='点击'/></td>"
    +"<td><input type='checkbox'/></td>"
    +"<td>hello</td>"
    +"</tr>");
    });
    });
    </script>
    </head>
    <body>
    <table width="200" border="1" id="table">
      <tr>
        <td>1</td>
        <td>2</td>
        <td>3</td>
      </tr>
      <tr>
        <td>4</td>
        <td>5</td>
        <td>6</td>
      </tr>
      <tr>
        <td>7</td>
        <td>8</td>
        <td>9</td>
      </tr>
    </table>
    <input type="button" id="btn" value="增加一行" />
    </body>
    </html>
      

  6.   

    LZ自己试试吧,俺也不知道你那控件好不好使…… <INPUT TYPE="button" VALUE="新建" ONCLICK="add()">
      <TABLE id="tab">
      <TR>
    <TH>textbox</TH>
    <TH>button</TH>
      </TR>
      </TABLE>
      <SCRIPT LANGUAGE="JavaScript">
      <!--
    function add(){
    var tab = document.getElementById("tab");
    var newrow = tab.insertRow();
    var newcell = newrow.insertCell();
    newcell.innerHTML = "<ig:WebTextEditor ID='txtLink' runat='server' Width='100%'/>";
    //newcell.innerHTML = '<INPUT TYPE="text" NAME="tbox">';
    var newcell = newrow.insertCell();
    newcell.innerHTML = '<INPUT TYPE="button" value="button">';
    }
      //-->
      </SCRIPT>