使用JavaScript添加表单字段..但在下面,而不是在一边? [英] using javascript to add form fields.. but below, not to the side?
本文介绍了使用JavaScript添加表单字段..但在下面,而不是在一边?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
因此,当我单击按钮时,javascript将添加新字段.当前,它会将新的文本框添加到侧面.是否可以在下面添加它?我想好像有一个
.这是代码.谢谢!
So as I click the button, the javascript adds new fields. Currently it adds the new text box to the side.. is there a way to make it add below? I guess as if there were a
.
Here is the code. Thanks!
<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的外观.
Insert a <br/>
tag infront of the inserted input or better yet, put the input into a div and control the look of it with CSS.
这篇关于使用JavaScript添加表单字段..但在下面,而不是在一边?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文