How do I add textboxes dynamically in Javascript?

后端 未结 8 853
感情败类
感情败类 2020-12-15 20:43

By default I have 5 textboxes. When a user clicks on a button, one textbox should be added.

How could I do this?

相关标签:
8条回答
  • 2020-12-15 21:36

    Best would be to attach an event on to the onclick of the button, that will set a div's visibility to inline. This is about the best way I can see for this, considering flexibility and robustness.

    Have a look here for example code.

    0 讨论(0)
  • 2020-12-15 21:38
    <script>
    function add()
    {
        var inpt = document.getElementById('input_template');
        inpt.parentNode.appendChild(inpt.cloneNode(false));
    }
    </script>
    
    <input type="button" onclick="add();">
    

    set id=input_template to one of the predefined textboxes

    0 讨论(0)
提交回复
热议问题