InnerHTML 在 Firefox 中警告时使用双引号,但在 IE 中则不警告

发布于 2024-08-30 22:59:48 字数 118 浏览 0 评论 0 原文

我制作innerHTML来获取数据并将其存储在数据库中。当我在 Firefox 中尝试时,属性的引号(“或')是正确的。但在 IE 中我没有得到属性的引号(“或')。这是浏览器问题吗?对此有任何答案。

谢谢

I make innerHTML to get data and store it in database. When i tried in firefox it is coming proper with quotes(" or ') for attributes. But in IE i am not getting the quotes(" or ') for attributes. Is this a browser issue? Any answer for this.

Thanks

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

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

发布评论

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

评论(2

泪痕残 2024-09-06 22:59:48

是的,这是一个浏览器问题,因为 IE 就是这样做的。请注意,并非 HTML 中的所有属性都必须使用引号,因此这不会使 IE 的输出无效。如果您想要 XHTML,则必须通过遍历 DOM 自行创建它。

Yes, this is a browser issue, in that that's just how IE does it. Note that quotes aren't mandatory for all attributes in HTML, so that doesn't make IE's output invalid. If you want XHTML you'll have to create it yourself by walking the DOM.

甩你一脸翔 2024-09-06 22:59:48

是的。当您使用 innerHTML 时,浏览器会根据 DOM 元素和元素中的属性重新创建 HTML。不同的浏览器的做法有所不同,因为直到最近还没有标准(innerHTML 是 Microsoft 的一项创新,几乎被其他所有人采用,并且正在 HTML5)。如果您的标记如下所示:

<span style="color: red" id="foo">...</span>

IE 的 innerHTML 将为:

<SPAN id=foo style="COLOR: red">...</SPAN>

...而 Firefox 和 Chrome 与您的原始标记非常接近。

IE 为您提供的是有效的 HTML(您可以省略其中不含空格的属性的引号,并且大写标记名也可以),但不是有效的 XHTML(如果这对您正在做的事情很重要) )。

如果您愿意,您可以通过自己遍历 DOM 树或对 IE 的结果进行后处理来构建自己的 (X)HTML 字符串。

好消息是,现在 innerHTML正在标准化,该标准明确表示结果应该是 XML 文档中的有效 XML(XHTML 文档就是),并且由于 Microsoft 比他们更积极地参与和致力于该领域的标准。多年来,IE9 在这方面可能会做得更好。

Yes. When you use innerHTML, the browser recreates the HTML based on the DOM elements and attributes in the element. Different browsers do so differently, because until recently there was no standard (innerHTML was a Microsoft innovation which was adopted by nearly everyone else, and is being standardized in HTML5). If your markup looks like this:

<span style="color: red" id="foo">...</span>

IE's innerHTML for that will be:

<SPAN id=foo style="COLOR: red">...</SPAN>

...whereas Firefox and Chrome are pretty close to your original.

What IE gives you is valid HTML (you're allowed to omit the quotes on attributes that don't have spaces in them, and UPPER CASE tagnames are okay too), but not valid XHTML (if that's important for what you're doing).

You can build your own (X)HTML string if you like by traversing the DOM tree yourself, or post-process IE's result.

The good news is that now that innerHTML is being standardized, and the standard clearly says that the result should be valid XML in an XML document (which XHTML documents are), and since Microsoft is more engaged and dedicated to standards in this area than they've been in years, it's likely that IE9 will do better in this regard.

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