Basic knowledge about createElement Event _ in javascript

Source: Internet
Author: User
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.

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.