守则:
var i=0,j=0;
var t1= new Array();
function createtext(){
i++;
t1[i]=document.createElement('input');
t1[i].type='text';
t1[i].name='text'+i;
t1[i].value = "hello"+i;
t1[i].size = 10;
document.forms[0].appendChild(t1[i]);
var mybr=document.createElement("<br>");
document.appendChild(mybr);
}
表格:
<form action="" method="get" name="f1">
<input name="b1" type="button" onClick="createtext()" value="+">
</form>
当单击“+”按钮时,文本框将向下生成,而不是向每个文本框的侧面生成..然后每个文本框在其旁边都有一个“删除”链接..当单击“删除”时,文本框将被删除。请帮助我。
------------------------------------------------
(+) <-imagine this is the button
[SAMPLETEXTBOX1] REMOVE <-imagine a textbox1 with remove link beside it
[SAMPLETEXTBOX2] REMOVE <-imagine a textbox2 with remove link beside it
[SAMPLETEXTBOX1] REMOVE <-imagine a textbox3 with remove link beside it
答案 0 :(得分:1)
您应该附加到form
,而不是document
,也可以使用document.createElement("br")
代替document.createElement("<br>")
。
var mybr=document.createElement("br");
document.forms[0].appendChild(mybr);
答案 1 :(得分:0)
对于添加,您可以将输入框和文本包装在DIV中,这样可以显示下面显示的控件的所需结果。
然后,当您单击删除时,您可以删除DIV元素,它可以使用它的所有子节点(输入和文本)。
答案 2 :(得分:0)
删除&lt;&gt;来自你的document.createElement