解决 HTML 在怪异模式下剥离引号的问题吗?

发布于 2025-01-07 14:55:37 字数 631 浏览 5 评论 0原文

当我尝试在 Javascript 中获取 InnerHTML 时,Firefox 给出了预期的结果。这样我就可以操作 dom 元素,但是当我使用相同的工作代码时,IE 会从属性对中去掉引号。我想知道是否有任何解决方法可以解决这个问题。如果可能的话,任何人都可以告诉我为什么它会渲染,因为怪癖模式还是什么?因为我的页面中有 iframe。 我的页面中有 DocType。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

预期:

<span id="someID">Ravi <span class="SomeClass">assignment </span>submission</span>

输出

<span id=someID>Ravi <span class=SomeClass>assignment </span>submission</span>

when i tried to get as InnerHTML in Javascript, Firefox giving expected results. so that i can manipulate the dom elements, bu when i use the same working code, IE will strip out the quotation marks from the attribute pair. i am wondering is there any work around to solve this problem. and if possible can any body tell me why does it renders, because of quirks mode or what ? as i have iframes in pages.
DocType which i have in my page.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

Expected :

<span id="someID">Ravi <span class="SomeClass">assignment </span>submission</span>

Output

<span id=someID>Ravi <span class=SomeClass>assignment </span>submission</span>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无语# 2025-01-14 14:55:37

< /code> 不会触发怪异模式,它会触发标准模式。

为什么缺少的引号让您烦恼?如果您想操作 DOM 元素,则不需要 innerHTML 字符串。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> doesn’t trigger quirks mode, it triggers standards mode just fine.

Why do the missing quotes bother you? If you want to manipulate the DOM elements, you don’t need the innerHTML string.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文