/** Use Dom to dynamically create elements. Note that the tr element cannot be directly attached to the appendchild method.
Add to the table element. The TR element must be appended to the tbody element with the appendchild method, and then
The appendchild method attaches the tbody to the table element. Otherwise, no error is reported on the page,
Is not displayed
*/
Function createtab (){
VaR etab = Document. createelement ("table ");
Etab. Border = 1; // The border is 1
VaR etbody = Document. createelement ("tbody ");
VaR etr1 = Document. createelement ("TR ");
VaR etr2 = Document. createelement ("TR ");
VaR etd1 = Document. createelement ("TD ");
VaR etd2 = etd1.clonenode (); // You can also use the clone method.
VaR etd3 = Document. createelement ("TD ");
VaR etd4 = Document. createelement ("TD ");
VaR etd5 = Document. createelement ("TD ");
VaR etd6 = Document. createelement ("TD ");
VaR txtnode1 = Document. createtextnode ("1 ");
VaR txtnode2 = txtnode1.clonenode (); // You can also use the clone method.
Txtnode2.nodevalue = "dfdf"; // use nodevalue to assign a value again.
VaR txtnode3 = Document. createtextnode ("3 ");
VaR txtnode4 = Document. createtextnode ("4 ");
VaR txtnode5 = Document. createtextnode ("5 ");
VaR txtnode6 = Document. createtextnode ("6 ");
Etd1.appendchild (txtnode1 );
Etd2.appendchild (txtnode2 );
Etd3.appendchild (txtnode3 );
Etd4.appendchild (txtnode4 );
Etd5.appendchild (txtnode5 );
Etd6.appendchild (txtnode6 );
Etr1.appendchild (etd1 );
Etr1.appendchild (etd2 );
Etr1.appendchild (etd3 );
Etr2.appendchild (etd4 );
Etr2.appendchild (etd5 );
Etr2.appendchild (etd6 );
Etbody. appendchild (etr1 );
Etbody. appendchild (etr2 );
Etab. appendchild (etbody );
Document. Body. appendchild (etab );
}
/* Use the innerhtml attribute of the page element to dynamically create the page element, which is used when adding text.
*/
Function createbyinnerhtml (){
VaR OBJ = Document. getelementbyid ("TT ");
OBJ. innerhtml = "<Table border = ''1''> <tr> <TD> dfdf </TD> </tr> </table> ";
}
</SCRIPT>
<Div id = "TT"> </div>