Elementary knowledge of createelement events in JavaScript

Source: Internet
Author: User

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.

Related Article

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.