我有一個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
不客氣! –