Home  >  Article  >  Web Front-end  >  Javascript solution to unknown runtime error when setting innerHTML under IE_javascript tips

Javascript solution to unknown runtime error when setting innerHTML under IE_javascript tips

WBOY
WBOYOriginal
2016-05-16 18:11:561140browse
Copy code The code is as follows:

<script> <br>document.getElementById("trone") .innerHTML = "<td>haha</td>"; <br></script>



In IE, "unknown runtime error (unknown runtime error)" sometimes occurs, but not in Firefox.

This is mainly because when IE writes innerHTML, it will check whether the element has the requirements to be used as an html object container in these contents. For example, if you add html containing
  • to a p Code, this is going to go wrong. So if you find these errors appearing, try to do two things:
    1. Check whether the html code you try to add to innerHTML contains broken html tags, such as no
      surrounded by < li>
    • .
      2. Change your container to a more "inclusive" tag, such as ,

      Special attention should be paid to the fact that adding the correctly formatted tag inside the , , tags may cause errors, so you should avoid using these tags as containers. You can use
      So, if it is
      use document.getElementById("trone").innerHTML="new"; there will be no problem.
      As a solution, you can use javascript to dynamically create tags such as
      instead of changing them directly using innerHTML.
      Statement:
      The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn