javascript - 使用 javascript 添加表单字段..但在下面,而不是在侧面?

标签 javascript html field

因此,当我单击按钮时,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/

相关文章:

Javascript带来外部文件的特定div

javascript - AngularJS $watch 函数重复调用 - 如何防止它

javascript - jquery 在子级中查找顶级表

javascript - 最佳实践 : Access form elements by HTML id or name attribute?

javascript - 设置单个单元格样式 js-xlsx, xlsx-style node.js

javascript - 最新的 requestAnimationFrame polyfill

javascript - 如何分别在桌面 View 和移动 View 中显示两个图像。

matlab - 在 Matlab 中,获取结构中的字段值

python - 为 Scapy 支持的字段查找字段大小(以字节为单位)

javascript - Yii2 禁用字段