The tbody innerHTML in IE6-IE9 cannot be assigned a value and the following code is reproduced
JS Code
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
var isupporttbodyinnerhtml = function () {
var table = document.createelement (' table ')
var tbody = document.creat Eelement (' tbody ')
table.appendchild (tbody)
var boo = True
try{
tbody.innerhtml = ' <tr></tr > '
catch (e) {
boo = False
} return
Boo
} ()
alert (isupporttbodyinnerhtml)
Click to see if you are browsing this blog at this time browser support
Click Me
<script type= "Text/javascript" >//<! [cdata[var isupporttbodyinnerhtml = function () {var table = document.createelement (' table ') var tbody = Document.create Element (' tbody ') var tr = document.createelement (' tr ') var td = Document.createelement (' td ') var txt = Document.createtext Node (' a ') td.appendchild (TXT) tr.appendchild (TD) Tbody.appendchild (TR) table.appendchild (tbody) var boo = True try{ tbody.innerhtml = ' <tr><td>b</td></tr> '} catch (e) {boo = false} Return boo} (); Tbodyinnerhtml.onclick = function () {if (isupporttbodyinnerhtml) {alert (' Your browser supports tbody innerhtml assignment ')} else {alert (' Your bangs The navigator is the ie6-9 kernel and does not support tbody innerHTML assignment ')}//]]></script>
For IE6-IE9, if you want to set tbody innerHTML, you can use the following workaround
JS Code
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
JS Code
function settbodyinnerhtml (tbody, HTML) {
var div = document.createelement (' div ')
div.innerhtml = ' <table > ' + HTML + ' </table> '
tbody.parentNode.replaceChild (Div.firstChild.firstChild, tbody)
}