Write a small system, you need to dynamically add form elements, according to their own implementation of the way to write this tutorial!
I think you have seen a similar effect on many websites!
1, first use the Document.createelement method to create an INPUT element!
The code is as follows:
var newinput = document.createelement ("input");
2, set related attributes, such as Name,type, etc.
The code is as follows:
Newinput.type=mytype;
Newinput.name= "INPUT1";
3, with AppendChild method, the element is appended to the content of a tag!
The code is as follows:
Temo.appendchild (Newinput);
Javascrip Core Code:
The 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 tag to be able to wrap!
Temo.appendchild (newline);
}
</script> write a small system, you need to dynamically add form elements, according to their own implementation method to write this tutorial!
I think you have seen a similar effect on many websites!
1, first use the Document.createelement method to create an INPUT element!
Copy CodeThe code is as follows:
var newinput = document.createelement ("input");
2, set related attributes, such as Name,type, etc.
Copy CodeThe code is as follows:
Newinput.type=mytype;
Newinput.name= "INPUT1";
3, with AppendChild method, the element is appended to the content of 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 tag to be able to wrap!
Temo.appendchild (newline);
}
</script>
JavaScript-implemented dynamic Add table cell Input,button, etc. (appendchild)