When writing a small system, you need to dynamically add form elements and write this tutorial in your own implementation method!
I think you have seen similar results on many websites!
1. Use the document. createelement method to create an input element!
CopyCode The Code is as follows: var newinput = Document. createelement ("input ");
2. Set relevant attributes, such as name and type.Copy codeThe Code is as follows: newinput. type = mytype;
Newinput. Name = "input1 ";
3. Use the appendchild method to append an element to a tag!Copy codeThe Code is as follows: temo. appendchild (newinput );
Javascrip core code:Copy codeThe Code is as follows: <script language = "JavaScript">
Function addelement (mytype ){
VaR mytype, temo = Document. getelementbyid ("add ");
VaR newinput = Document. createelement ("input ");
Newinput. type = mytype;
Newinput. Name = "input1 ";
Temo. appendchild (newinput );
VaR newline = Document. createelement ("Br"); // create a br label for newline!
Temo. appendchild (newline );
}
</SCRIPT>
>