When we use the Createelemen method t to create an element node, it seems to be able to write under IE, but switching to FF and other browsers will always error.
For example, if we want to create an INPUT element, then under IE, we can have a variety of ways:
To test a situation, note the other situation:
<script type= "Text/javascript" >
The first, along with attributes, is created
var x = document.createelement ("<input type= ' text ' size= '/>");
Second, create in an empty label form
var x = document.createelement ("<input/>");
Third, created in the form of tagname
var x = document.createelement ("input");
Document.body.appendChild (x);
</script>
The above 3 kinds of ways in IE can pass, and then non-IE core browser (such as FF,OP,SF, etc.), the first 2 kinds of writing will be error, can not create this input element correctly.
The standard is written as a 3rd, and the browser is accurate.
Because the attributes of the element can be created together when creating an element node in IE using the CreateElement method, this is not possible 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>
Add a property on Document.setattribute ("attribute", "value") once.
Later found that actually 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, it seems that not all attributes can be created, such as input size,value,class and so on in this way can not be created, for specific reasons I am not clear. So it is recommended to use the previous wording.
Use of the Document.createelement method