html结构错误小记

这段代码,IE下报错:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"/>
<title>test</title>
</head>
<body >
hello
</body>
<script>
document.body.innerHTML
='<p><pre>ddd<br></pre></p>';
</script>
</html>

原因 (感谢网友貘给出解答):

The P element represents a paragraph. It cannot contain block-level elements (including P itself).
http://www.w3.org/TR/html401/struct/text.html#edef-P

更多内空(感谢网友GrayZhang提供):

这里有对应的各元素,点进去能看到元素的具体额外内容模型
http://dev.w3.org/html5/markup/elements.html
这个是general的内容模型
http://dev.w3.org/html5/markup/common-models.html

原文地址:https://www.cnblogs.com/jkisjk/p/html_unfit.html