This article uses examples to briefly introduce the createElement event in javascript. For more information, see createElement. It is the concept of using W3C DOM to create a subnode, that is, a subelement, in HTML.
The Code is as follows:
Script
Window. onload = function (){
Var input = document. createElement ('input ');
Var button = document. createElement ('input ');
Input. type = 'text ';
Input. id = 'text ';
Input. value = '1 ';
Button. type = 'button ';
Button. value = 'add by add ';
Button. style. width = '40px ';
Button. style. height = '23px ';
Document. body. appendChild (input );
Document. body. appendChild (button );
Button. onclick = function (){
Var value = input. value;
Input. value = value * 1 + 1;
}
}
Script
Note: value is actually a character. value = value * 1 + 1; input. value = value + 1; then the result will show 111111, which is continuously added in the form of characters, so the value * 1 can be converted to the Int type.
Summary:
To finally solve the compatibility problem of the createElement method, you still need to judge the browser. for IE, you can use its unique method to pass in a valid HTML code string for createElement as a parameter, non-IE browsers still use W3C standard methods.