IE6/IE7/IE8/IE9 tbody innerHTML The perfect solution to be able to assign value-experience Exchange

Source: Internet
Author: User
IE6/IE7/IE8/IE9 tbody innerHTML cannot be assigned, reproduce the code as follows

Copy the Code code as follows:




Tbody innerHTML in IE6-IE9 cannot copy a bug






Aaa


GET SET





Two buttons, the first to get Tbody's innerHTML, and the second to set the Tbody innerHTML.

Obtained when all browsers pop up the TR string, but the settings ie6-9 not support, and error,

You can use the feature to determine whether the browser supports TBODY innerHTML setting values

Copy the 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 = ' '
} 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 the Code code as follows:
function settbodyinnerhtml (tbody, HTML) {
var div = document.createelement (' div ')
div.innerhtml = '

' + HTML + '
'
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 add the first element of the first element of the div to Tbody, which is div>table>tr.

Of course there is a more streamlined version, which is replaced directly by the ReplaceChild method

Copy the Code code as follows:
function settbodyinnerhtml (tbody, HTML) {
var div = document.createelement (' div ')
div.innerhtml = '

' + HTML + '
'
Tbody.parentNode.replaceChild (Div.firstChild.firstChild, tbody)
}

The innerHTML of Col, Colgroup, frameset, HTML, head, style, table, TFOOT, THead, title, and TR are read-only (IE6-IE9) from the record on MSDN.

The InnerHTML property was 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 the title element using the Document.title property.

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 cells, you can use InnerHTML.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.