The way Javascript generates HTML elements is described in this article in 2, the first is a more formal method of creating elements, and the second is to use the Write () method in JavaScript to write HTML elements directly.
Method One:
Copy Code code as follows:
createelement () create INPUT element into obj object
var obj = document.createelement (' input ');
Select the previous element where you want to build the site
var before = document.getElementById (' before ');
Set obj element name, value
Obj.name= ' name ';
Obj.value= ' value ';
SetAttribute are free to define attributes, not only the IDs and Type,name and value can also be defined in this
Obj.setattribute (' id ', ' idname ');
Obj.setattribute (' type ', ' TypeName ');
Add obj after the previous element
Before.appendchild (obj);
Method Two:
Copy Code code as follows:
document.write ("<inpt name= ' name ' value= ' value ' id= ' idname ' type= ' TypeName ' >");
Here is a list of these 2 ways to generate HTML <input> elements, the first comparison specification, the code is more, the second relatively little code.