The tbody innerHTML in IE6/IE7/IE8/IE9 cannot be assigned a value and the following code is reproduced
Copy Code code as follows:
<! DOCTYPE html>
<meta charset= "Utf-8"/>
Tbody innerHTML cannot be duplicated in <TITLE>IE6-IE9 bug</title>
<body style= "height:3000px" >
<table>
<tbody>
<tr><td>aaa</td></tr>
</tbody>
</table>
<p>
<button id= "btn1" >get</button><button id= "BTN2" >SET</button>
</p>
<script>
var tbody = document.getelementsbytagname (' tbody ') [0]
function Settbody () {
tbody.innerhtml = ' <tr><td>bbb</td></tr> '
}
function Gettbody () {
Alert (tbody.innerhtml)
}
Btn1.onclick = function () {
Gettbody ()
}
Btn2.onclick = function () {
Settbody ()
}
</script>
</body>
Two buttons, the first to get the Tbody innerHTML, and the second to set the Tbody innerHTML.
When obtained, all browsers pop up the TR string, but the ie6-9 is not supported when set and the error is shown
You can use the feature to determine whether the browser supports TBODY innerHTML setting values
Copy Code code as follows:
var isupporttbodyinnerhtml = function () {
var table = document.createelement (' table ')
var tbody = document.createelement (' tbody ')
Table.appendchild (TBODY)
var Boo = True
try{
tbody.innerhtml = ' <tr></tr> '
catch (e) {
Boo = False
}
Return Boo
}()
Alert (isupporttbodyinnerhtml)
For IE6-IE9, if you want to set tbody innerHTML, you can use the following workaround
Copy Code code as follows:
function settbodyinnerhtml (tbody, HTML) {
var div = document.createelement (' div ')
div.innerhtml = ' <table> ' + html + ' </table> '
while (Tbody.firstchild) {
Tbody.removechild (Tbody.firstchild)
}
Tbody.appendchild (Div.firstChild.firstChild)
}
Use a div to include a table, then delete all the elements in the tbody, and finally give Tbody the first element of the first element of the Div, that is, div>table>tr.
There is, of course, a more streamlined version, which uses the ReplaceChild method directly to replace
Copy Code code as follows:
function settbodyinnerhtml (tbody, HTML) {
var div = document.createelement (' div ')
div.innerhtml = ' <table> ' + html + ' </table> '
Tbody.parentNode.replaceChild (Div.firstChild.firstChild, tbody)
}
The tHead of Col, Colgroup, frameset, HTML, head, style, table, TFOOT, innerHTML, title, and TR are read-only (IE6-IE9) from the MSDN records.
The InnerHTML property is read-only on the col, Colgroup, FrameSet, HTML, head, style, table, Tbody, TFoot, THead, title, and TR objects.
You can change the value of the title element using the Document.title property.
To change the contents of the table, TFoot, THead, and TR elements, use the "Table object model described in building table" S dynamically. However, to change the content of a particular cell, your can use InnerHTML.