(1)
The operations on table labels vary with ie, firefox, and other browsers. in ie, assigning values to innerHTML of table and tr is not allowed. When adding a tr using js, the appendChile method does not work. The following is my test results for the three browsers:
InsertRow
IE6: supported, and the default parameter is-1. It is added to the end by default.
FireFox: supported, but the default parameters are supported.
Opera: supported. default parameters are supported. It is added to the beginning by default.
AppendChild
IE6: not supported
FireFox: Yes, but adding TR does not affect ROWS.
Opera: supported. The effect is the same as that of insertRow (-1), which affects ROWS.
By following the specifications to the maximum extent, you can write safe and applicable code:
// Append an empty row to the table:
Var otr = otable. insertRow (-1 );
Var otd = document. createElement ("td ");
Otd. innerHTML = "";
Otd. className = "XXXX ";
Otr. appendChild (otd );
In this way, you can run on these three browsers.
(3) childNodes operations
(1) attribute nodeName
Utils. getChildrenByTagName = function (node, tagName ){
Var ln = node. childNodes. length;
Var arr = [];
For (var z = 0; z <ln; z ++ ){
If (node. childNodes [z]. nodeName = tagName ){
Arr. push (node. childNodes [z]);
}
}
Return arr;
};
(2) Property id
Function getNodeID (parent, id ){
Var ln = parent. childNodes. length;
For (var z = 0; z <ln; z ++ ){
If (parent. childNodes [z]. id = id ){
Return parent. childNodes [z];
}
}
Return null;
}
(3) attribute className
Corresponding class, such as <tr class = "class1">
Function getElementsByClassName (node, className ){
Var children = node. getElementsByTagName ("*");
Var elements = new Array ();
For (var I = 0; I <children. length; I ++ ){
Var child = children [I];
Var classNames = child. className. split ("");
For (var j = 0; j <classNames. length; j ++ ){
If (classNames [j] = className ){
Elements. push (child );
Break;
}
}
}
Return elements;
}