innerHTML未知的运行错误
代码:















运行以上代码,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的一些问题”。
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET制作智能桌面机器人:结合BotSharp智能体框架开发语音交互
· 软件产品开发中常见的10个问题及处理方法
· .NET 原生驾驭 AI 新基建实战系列:向量数据库的应用与畅想
· 从问题排查到源码分析:ActiveMQ消费端频繁日志刷屏的秘密
· 一次Java后端服务间歇性响应慢的问题排查记录
· 互联网不景气了那就玩玩嵌入式吧,用纯.NET开发并制作一个智能桌面机器人(四):结合BotSharp
· Vite CVE-2025-30208 安全漏洞
· 《HelloGitHub》第 108 期
· MQ 如何保证数据一致性?
· 一个基于 .NET 开源免费的异地组网和内网穿透工具