CreateElement is the concept of establishing child nodes, which are child elements, in HTML with the application of the consortium DOM to the image model.
Copy Code code 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 ';
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, if will input.value=value*1+1; input.value=value+1, the result will appear 111111, he is constantly in character form plus 1, so this time value* A value of 1 can be converted to an int type.
Summarize:
In order to solve the compatibility problem of createelement method, still pay attention to judge the browser, for IE can use its unique method by passing a valid HTML code string for createelement, and non IE browsers still use the standard method of the Web standard.