我有一个html表单,我想添加输入字段来使用javascript。本来我自己有输入字段的“身体”的下面,其次为能够添加字段:将输入添加到html表单,使用javascript
// Create number input field
var phoneInput = document.createElement("INPUT");
phoneInput.id = "phone" + instance;
phoneInput.name = "phone" + instance;
phoneInput.type = "text";
// Insert that stuff
document.body.insertBefore(document.createElement("BR"), element);
document.body.insertBefore(phoneLabel, element);
document.body.insertBefore(phoneInput, element);
然后我在HTML文件中添加了一个“形式”元素周围原来的输入。
<body>
<form action=searchform.php method=GET>
<LABEL for="phone1">Cell #: </LABEL>
<input id="phone1" type="text" name="phone1">
<input type="button" id="btnAdd" value="New text box" onclick="newTextBox(this);" />
</form>
</body>
现在按钮不会添加新的文本框。我的结构是否有误? 谢谢!
嗯,柜面身体有很多更孩子,有没有一种方法,我可以用一个ID标签的形式,然后有insertBefore指向呢?谢谢。 – Matt
没有看到答复的其余部分。谢啦! – Matt
不客气! –