所以當我點擊按鈕時,javascript添加了新的字段。目前它將新的文本框添加到邊..有沒有辦法讓它在下面添加?我猜想好像有一個
。 這是代碼。謝謝!使用JavaScript來添加表單域..但下面,而不是一邊?
<html>
<head>
<script type="text/javascript">
var instance = 1;
function newTextBox(element)
{
instance++;
var newInput = document.createElement("INPUT");
newInput.id = "text" + instance;
newInput.name = "text" + instance;
newInput.type = "text";
//document.body.write("<br>");
document.body.insertBefore(newInput, element);
}
</script>
</head>
<body>
<input id="text2" type="text" name="text1"/> <br>
<input type="button" id="btnAdd" value="New text box" onclick="newTextBox(this);" />
</body>