代码:

innerHTML未知的运行错误<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
innerHTML未知的运行错误
innerHTML未知的运行错误
<html xmlns="http://www.w3.org/1999/xhtml">
innerHTML未知的运行错误
<head>
innerHTML未知的运行错误    
<title>innerHTML未知的运行错误</title>
innerHTML未知的运行错误
</head>
innerHTML未知的运行错误
<body>
innerHTML未知的运行错误
<id="p"></p>
>

运行以上代码,IE里提示:未知的运行错误。FF测试是正确的。
Goole一下,innerHTML 对下面的对象只读(<=IE7):table,thead,tfoot,tbody,tr,col,colgroup,html,title,style,frameset等。

上面所说的innerHTML属性只读的对象中并不包括p,为什么还报错。
再google,找到这么一段:

The <p> tag can be nested within certain tags and certain tags can be nested within it. The general rule is that the paragraph has to be its own block. Therefore, a paragraph tag cannot be nested within a tag expecting only text or inline elements, nor can another block element tag be nested within a paragraph tag.
For instance, you cannot nest paragraph tags and heading tags.
You can also put paragraph tags within division tags but not the other way around.
A paragraph tag can be placed within a table cell or other tags structures that are not text only. It can also be placed within a list item. This means you can have long, multi-paragraph list items. Anything can be nested within a <p> tag that is allowed within the flow of the text. All style tags are allowed within a paragraph since they format text. Links and images can be placed within paragraphs, and the <br /> tag exists for the exclusive purpose of breaking the line without ending the paragraph.
If a Web browser encounters a tag within a paragraph that cannot be nested within paragraph tags, it will assume that the paragraph has ended.

大家自己看吧, 其中的大意之一:p标签不能包容div、h1除了<br />等块级元素。

所以IE报未知的运行错误原因就是innerHTML里有div标签,另外往p元素里插入div元素也会失败 【p.appendChild(div)】
最后,蓝色理想上的一篇blank的“innerHTML的一些问题”。

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-03
  • 2022-02-27
  • 2022-12-23
  • 2021-08-22
  • 2022-12-23
猜你喜欢
  • 2021-11-01
  • 2021-07-05
  • 2022-12-23
  • 2021-07-02
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案