Article Introduction: The similarities and differences of createelement in each browser. |
When we create an element node using the Createelemen method, other browsers such as IE and FF will be different.
If we create an INPUT element, under IE, we can have a variety of ways:
<script type= "Text/javascript" >
The first, together with attributes, is created
var x = document.createelement ("<input type= ' text ' size= '/>");
The second type is created in the form of an empty label
var x = document.createelement ("<input/>");
The third type, created in tagname form
var x = document.createelement ("input");
Document.body.appendChild (x);
</script>
All of the above 3 ways in IE can be used, and then no more than IE core browser (such as FF,OP,SF, etc.), the first 2 kinds of writing will be an error, can not correctly create this INPUT element.
Because an element node is created with the CreateElement method in IE, the attributes of that element can be created together, but this is not feasible in other browsers, so we have to create its properties in other ways.
To create a standard notation for an element node with attributes:
<script type= "Text/javascript" >
var x = document.createelement ("input");
X.setattribute ("type", "text");
X.setattribute ("Size", "30");
Document.body.appendChild (x);
</script>
Adding an attribute is Document.setattribute ("attribute", "value") once.
Later found that in fact can also write:
<script type= "Text/javascript" >
var x = document.createelement ("input");
X.type = "text";
Document.body.appendChild (x);
</script>
But using this to create properties, as if not all of the attributes can be created, such as the input of the size,value,class and so in this way can not be created, as for the specific reasons I am not clear. So it is recommended that you use the previous wording.