Unknown runtime error in Javascript innerhtml

Source: Internet
Author: User

Use innerhtml to add interface elements.
For example.
. Html
<Table id = "tab_1" width = "100%" border = "0"> </table>

. Js
Document. getelementbyid ("tab_1 "). innerhtml = "<tr> <TD colspan =" 5 "> <Div class =" double "> <span> some: </span> </div> </TD> </tr> ";
In IE, "unknown runtime error" may sometimes occur )",
But not in Firefox.

This is mainly because IE checks whether tab_1 meets the requirements of HTML object containers in the content when writing innerhtml. Therefore, if you find these errors, try to do two things:

1. Check the HTML you are trying to add to innerhtmlCodeContains damaged HTML tags. For example, <ul> </ul> <li> </LI> is not contained.
2. Change your container to the "inclusive" labels, such as <span> </span>, <div> </div>

Note that errors may occur when the <tbody>, <Table>, and <tr> label is correctly formatted. Therefore, avoid using these labels as containers.
If necessary, you can use <TD> as a container, and then use another layer of table.

 

------------------------------------

There are two reasons
1. The innerhtml attribute of the element is read-only ..
Read-Only elements: Col, colgroup, frameset, Head, HTML, style, table, tbody, tfoot, thead, title, tr

2. For example, if the innerhtml attribute of the DIV is modified when the DIV is nested in P, an error occurs.

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.