Home > Web Front-end > JS Tutorial > body text

A brief discussion on the createElement event in javascript_Basic knowledge

WBOY
Release: 2016-05-16 16:28:53
Original
1705 people have browsed it

createElement is a concept in HTML that uses the W3C DOM object model to create child nodes, that is, child elements

Copy code The code is as follows:

<script><br> window.onload = function () {<br> var input = document.createElement('input');<br> var button = document.createElement('input');<br> input.type ='text'; <br> input.id= 'text';<br> input.value ='1';<br> button.type='button';<br> button.value ='Add step by step';<br> button.style.width = '40px';<br> button.style.height = '23px';<br> Document.body.appendChild(input);<br> Document.body.appendChild(button);<br> button.onclick = function(){<br> var value = input.value;<br> Input.value = value * 1 1;<br> }<br> }<br> </script>

Note: value is actually a character. If input.value=value*1 1; is replaced by input.value=value 1;, the result will be 111111. It keeps adding 1 in the form of characters, so at this time Value*1 can convert the value value into Int type.

Summary:

To finally solve the compatibility problem of the createElement method, you still need to pay attention to the browser. For IE, you can use its unique method of passing a legal HTML code string as a parameter to createElement. Non-IE browsers still use it. Standard approach to W3C specifications.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!