<input type="button" value="增加输入框" onclick="addInput()"/>
<table id="t">
<tr><td>框前名字1</td><td><input type="text" name="name[]" value=''></td><td><a href='#' onclick="javascript:delInput(this)">删除这个框</a></td></tr>
<tr><td>框前名字2</td><td><input type="text" name="name[]" value=''></td><td><a href='#' onclick="javascript:delInput(this)">删除这个框</a></td></tr>
</table>
<SCRIPT LANGUAGE="JavaScript">
<!--
function addInput()
{
var t = document.getElementById("t");
var tr= t.childNodes[0].lastChild;
var n = tr.cloneNode(true);
n.childNodes[0].innerHTML = "框前名称" + (parseInt(n.childNodes[0].innerHTML.replace(/(\D+)/,""))+1);
t.childNodes[0].insertBefore(n);
}
function delInput(a)
{
while(a.tagName.toUpperCase() != "TR")
a = a.parentNode;
a.parentNode.removeChild(a);
}
//-->
</SCRIPT>

解决方案 »

  1.   

    <div id="myform"><input name="aa"><input type="button" onclick="add()"></div>
    <script language="javascript">
      function add(){
        obj = document.getElementById("myform");
        obj.innerHTML = "<input type="text" name="bb">" + obj.innerHTML;
      }
    </script>
      

  2.   

    <SCRIPT language="javascript">
    var row = 0;function insertElement() {
      var nod=document.createElement("span");
      document.form1.insertBefore(nod);
      nod.innerHTML="<br>row"+row+"<input type=text name=txt["+row+"][]><input type=text name=txt["+row+"][]>"
      row = row+1
    }
    </SCRIPT><BODY>动态增加文本框<form name=form1 action=<? echo $PHP_SELF; ?> method=POST>
    <input type=submit value="提交"><input type=button value=增加 onclick="insertElement()"><br>
    </form>
    <pre>
    <?
    print_r($HTTP_POST_VARS);
    ?>
    </pre></BODY>