Home > Web Front-end > JS Tutorial > body text

Javascript在IE下设置innerHTML时出现未知的运行时错误的解决方法_javascript技巧

WBOY
Release: 2016-05-16 18:11:56
Original
1101 people have browsed it
复制代码 代码如下:

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



在IE中,有时候会出现"未知的运行时错误(unknown runtime error)",而在firefox里不会。

这主要是IE在对innerHTML进行写操作的时候会检查element是否具备做为这些内容中html对象容器的要求,比如如果你是在一个p里加入包含
  • 的html代码,这是会出错的。所以如果你发现这些错误出现,尝试做两件事情:
    1、检查你尝试加到innerHTML的html代码是否包含破损的html标签,如没有
      包围的
    • .
      2、把你的容器改成那些比较“包容”的标签,如,

      特别注意的是,,标签里面加正确格式的使用document.getElementById("trone").innerHTML="new";就没问题。
      解决方法你可以用javascript动态创建
      标签都有可能出错,所以应该避免使用这些标签作为容器,必要时可以用 作为容器,再嵌套一层表格。

      所以,如果是
      等标签,而不是用innerHTML直接改。
    • Related labels:
      source:php.cn
      Statement of this Website
      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
      Popular Tutorials
      More>
      Latest Downloads
      More>
      Web Effects
      Website Source Code
      Website Materials
      Front End Template
      About us Disclaimer Sitemap
      php.cn:Public welfare online PHP training,Help PHP learners grow quickly!