JavaScript-implemented dynamic Add table cell Input,button, etc. (appendchild)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.