因此,当我单击按钮时,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>
最佳答案
插入<br/>
在插入的输入前面添加标签,或者更好的是,将输入放入 div 中并使用 CSS 控制它的外观。
关于javascript - 使用 javascript 添加表单字段..但在下面,而不是在侧面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1950837/