Let the ie6-ie9 support table. innerHTML, in fact, this is just the processing of the table, the other unsupported elements can use a similar solution to test the Code:
The Code is as follows:
Script
Var oTable = document. getElementById ("test ");
OTable. innerHTML ="InnerHTML";
Script
The above Code does not work in the IE6-9 and an error is reported directly:
IE9: Invalid target element for this operation.
IE6-8: Unknown runtime error
Find the IE document (http://msdn.microsoft.com/en-us/library/ms533897 (VS.85). aspx) and find such a paragraph:
The InnerHTML Property is read-only on Col, ColGroup, FrameSet, Html, Head, Style, Table, TBody, TFoot, THead, Title, And Tr Objects.
So we can only use other solutions. My solutions:
The Code is as follows:
Var oTable = document. getElementById ("test ");
// OTable. innerHTML ="InnerHTML";
SetTableInnerHTML (oTable ,"InnerHTML");
Function setTableInnerHTML (table, html ){
If (navigator & navigator. userAgent. match (/msie/I )){
Var temp = table. ownerDocument. createElement ('P ');
Temp. innerHTML ='
';
If (table. tBodies. length = 0 ){
Var tbody = document. createElement ("tbody ");
Table. appendChild (tbody );
}
Table. replaceChild (temp. firstChild. firstChild, table. tBodies [0]);
} Else {
Table. innerHTML = html;
}
}
Here, we only process the table and use a similar solution for other unsupported elements.
In addition, table in IE10 supports innerHTML.
Author: Artwl