Adding textbox on button click with javascript

前端 未结 2 886
时光说笑
时光说笑 2021-01-16 22:15

I\'m working on a web form with a textbox for pets and an \"add pet\" button. Each time the button is clicked, an additional textbox should be displayed below the original o

2条回答
  •  一向
    一向 (楼主)
    2021-01-16 22:40

    Something like this?

    Pets:


    document.getElementById("addPet").onclick = function() {
        var form = document.getElementById("myForm");
        var input = document.createElement("input");
        input.type = "text";
        var br = document.createElement("br");
        form.appendChild(input);
        form.appendChild(br);
    }
    

    Edit: I'd suggest using a table to style the input boxes, keep them in line. FIDDLE

提交回复
热议问题