JavaScript the solution of unknown run-time error when setting innerHTML in IE _javascript tips

Source: Internet
Author: User
Copy Code code as follows:

<script>
document.getElementById ("Trone"). InnerHTML = "<td>haha</td>";
</script>
<tr id= "Trone" >
</tr>

In IE, there are sometimes "unknown run-time errors" (Unknown runtime error), but not in Firefox.

This is mainly the case of IE in the write operation of the innerHTML will check whether the element has to do as the content of the HTML object container requirements, such as if you are in a P containing <li> HTML code, this will be wrong. So if you find these errors appearing, try to do two things:
1, check your attempt to add to the innerHTML HTML code contains broken HTML tags, such as no <ul></ul> surrounded by <li></li>
2, change your container to those more "inclusive" label, such as <span></span>,<div></div>
The special note is that the <tbody>,<table>,<tr> tags in the correct format <td> tags may be wrong, so you should avoid using these labels as a container, if necessary, can use <td> as a container , and then nest a layer of tables.

So, if it is
<TD id= "Trone" ></td> use document.getElementById ("Trone"). innerhtml= "new"; no problem.
Workaround you can dynamically create <tr><td> tags with javascript, instead of using innerHTML to change directly.
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.