How to solve unknown runtime errors when Javascript sets innerHTML in IE

Source: Internet
Author: User

Copy codeThe Code is as follows: <script>
Document. getElementById ("trone"). innerHTML = "<td> haha </td> ";
</Script>
<Tr id = "trone">
</Tr>

In IE, "unknown runtime error" may sometimes occur, but not in firefox.

This is mainly because when IE writes innerHTML, it will check whether the element meets the requirements of the html object container in the content, for example, if you add html code containing <li> In A p file, this will cause an error. So if you find these errors occur, try to do two things:
1. Check whether the html code you tried to add to innerHTML contains broken html tags. For example, <li> </li> is not surrounded by <ul> </ul>.
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> labels in the correct format are added to the <td> labels. Therefore, avoid using these labels as containers, if necessary, you can use <td> as a container and then nest a table.

Therefore
<Td id = "trone"> </td> use document. getElementById ("trone"). innerHTML = "new.
You can use javascript to dynamically create <tr> <td> and other labels instead of using 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.