Home > Web Front-end > JS Tutorial > Dynamically adding form elements input, button, etc. (appendChild) implemented in javascript_javascript skills

Dynamically adding form elements input, button, etc. (appendChild) implemented in javascript_javascript skills

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 19:07:37
Original
1499 people have browsed it

When writing a small system, you need to dynamically add form elements, so I wrote this tutorial according to my own implementation method!
I think you have seen similar effects on many websites!
1. Use document first. The createElement method creates an input element!

Copy code The code is as follows:

var newInput = document.createElement("input");

2. Set related attributes, such as name, type, etc.
Copy code The code is as follows:

newInput.type=mytype;
newInput.name="input1";

3. Use the appendChild method to append elements to the content of a tag !
Copy code The code is as follows:

TemO.appendChild(newInput);

Javascrip core code:
Copy code The code is as follows:




[Ctrl A select all Note: If you need to introduce external Js, you need to refresh to execute
]
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
What are JavaScript hook functions?
From 1970-01-01 08:00:00
0
0
0
What is JavaScript garbage collection?
From 1970-01-01 08:00:00
0
0
0
c++ calls javascript
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template