Today, I handled the compatibility problem of ie and ff for a date selector. It was difficult to find an error in this case. After a long time, I found the error and found the method document for creating elements in js. createElement (). This
Getelementbyid getelementsbyname getelementsbytagname
Getelementbyid obtains the node through the ID attribute of the node. This object contains attributes such as nodename, nodetype, parentnode, and childnodes.
Nodename indicates the node name. If
// Create a label by defining the Method//*************************************//Copy codeThe Code is as follows:Var createLabel = function (id, name, value ){Var label_var = document. createElement ("label ");Var label_id = document.
//*************************************//
// Create a label by defining the Method
//*************************************//
VaR createlabel = function (ID, name, value ){
VaR label_var = Document. createelement ("label ");
VaR
As a js-DOM developer, you must know some DOM methods:1. Create a node.CreateElement ():Var a = document. createElement ("p ");It creates an element node, so nodeType is equal to 1.A. nodeName will return p;Note: The new element node created by the
When analyzing the code, I found my blind spot-document. createelement (), surfing, and summed up some experience.
Document. createelement () is to create an object in the object, with the appendchild () orThe insertbefore () method is used
When we need to dynamically generate DOM objects, we will use the createElement method to create them. However, in IE and Firefox, The createElement method is different.
In IE, you can use either of the following methods to create an element:
1.
During web development, JavaScript is often used to dynamically create HTML elements and set relevant attributes. For example, if you want to create a div layer, you can use the following
Code .
1. directly establish
Function
Button1_onclick ()
AnalysisCodeFind your own blind spot-document. createelement (), surf and summarize some experience.
Document. createelement () is an object created in the object. It must be used together with the appendchild () or insertbefore () method. The
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.