IE6-9 does not support solutions for table. innerhtml

Source: Internet
Author: User

TestCode:

 <  Table  ID  = "Test"  >  </  Table  >  <  Script  >      VaR  Otable  = Document. getelementbyid (  "  Test  "  ); Otable. innerhtml  =  "  <Tr> <TD> innerhtml </TD> </tr>  "  ;  </  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: 

VaR Otable = Document. getelementbyid ("test" );  //  Otable. innerhtml = "<tr> <TD> innerhtml </TD> </tr> "; Settableinnerhtml (otable, "<tr> <TD> innerhtml </TD> </tr>" );  Function  Settableinnerhtml (table, HTML ){  If (Navigator & navigator. useragent. Match (/MSIE/ I )){  VaR Temp = table. ownerdocument. createelement ('div'); Temp. innerhtml = '<Table> <tbody>' + HTML + '</tbody> </table>' ;  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.

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.