向 div 和 span 添加 rel 或 name 属性是否会导致 IE/FF 进入怪异模式?

发布于 2024-08-20 21:07:52 字数 343 浏览 5 评论 0原文

标签是否会将

<span id="suchAndSuch" class="blah" rel="this.that.other" name="this.name"></span>

IE

<div id="suchAndSuch" class="blah" rel="this.that.other" name="this.name"></div>

和/或 FF 扔给 QM?根据 W3C 的说法,这些不是这些标签的标准属性,但没有说明是否会使它们无效。

非常感谢您的帮助。

Will a tag like

<span id="suchAndSuch" class="blah" rel="this.that.other" name="this.name"></span>

or

<div id="suchAndSuch" class="blah" rel="this.that.other" name="this.name"></div>

throw IE and/or FF to QM? According to W3C, those aren't standard attributes for those tags, but it does not say if it'll make them invalid.

Your help is much appreciated.

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

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

发布评论

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

评论(5

没有你我更好 2024-08-27 21:07:53

不,它不会让浏览器进入怪异模式。在 DOCTYPE 之前没有 DOCTYPE 或没有 HTML 注释(或任何 HTML 内容)将使浏览器进入怪异模式。

如果您可以避免使用自定义属性,那么您应该这样做。如果不能,您可能需要考虑使用 HTML5 文档类型,然后使用 data 属性。例如,您编写的内容可以这样完成:

<div id="suchAndSuch" class="blah" data-references="this.that.other" data-name="this.name"></div>

这仍然有效,并且受到现代浏览器(甚至许多旧浏览器)的支持。

No, it will not throw a browser into quirks mode. Not having a DOCTYPE or having a HTML comment (or any HTML content) before a DOCTYPE will throw browsers into quirks mode.

If you can avoid using custom attributes, you should. If you cannot, you might want to consider using a HTML5 doctype, and then using data attributes. For instance, what you wrote could be done like this:

<div id="suchAndSuch" class="blah" data-references="this.that.other" data-name="this.name"></div>

And that would still be valid, as well as supported by modern browsers (and even a number of older ones).

柠檬色的秋千 2024-08-27 21:07:53

您必须使用有效的文档类型,并且它必须是文件中找到的第一个内容。我还没有测试严格的文档类型和自定义属性的行为,但我确信过渡文档类型可以与自定义属性一起使用。

我认为关键是要有一个有效文档类型:

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

You have to be using a valid doctype and it needs to be the first thing found in the file. I haven't tested the behavior of a strict doctype and custom attributes but I know for sure that a transitional doctype works with custom attributes.

I think the key is to have a valid doctype:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
一城柳絮吹成雪 2024-08-27 21:07:53

怪异模式只能根据为文档指定的(缺少)DOCTYPE 来触发。

FirefoxIE,您可以通过在地址栏中粘贴以下内容来检查文档的模式:

javascript:alert(document.compatMode)

com document.compatMode 的值为 BackCompat (对于怪异模式)和 CSS1Compat (对于标准/严格模式)。

在 Firefox 中,您还可以右键单击文档,然后单击“查看页面信息”。该模式将在顶部附近列为“渲染模式”。

Quirks mode should only ever be triggered based on the (lack of) DOCTYPE specified for the document.

In Firefox or IE, you can check the mode of a document by pasting the following in your address bar:

javascript:alert(document.compatMode)

The valid values for document.compatMode are BackCompat (for quirks mode) and CSS1Compat (for standards/strict mode).

In Firefox, you can also right-click on a document and click "View Page Info". The mode will be listed near the top as "Render Mode".

土豪 2024-08-27 21:07:53

您可以通过以下方式检查页面的呈现方式:

在 Firefox 中,转到“工具”>“页面”。页面信息并查看“渲染模式”。

在 IE8 中单击“工具”>“开发人员工具并查看右上角的“文档模式”。

例如,此页面在 Firefox 中以“标准合规模式”呈现,在 Internet Explorer 中以“IE8 标准”呈现。

You can check how a page is being rendered by the following:

In Firefox go to Tools > Page Info and look at the 'Render Mode'.

In IE8 click on Tools > Developer tools and look at the 'Document Mode' at the top right.

For example, this page is rendered in 'Standards compliance mode' in Firefox and 'IE8 Standards' in Internet Explorer.

无畏 2024-08-27 21:07:53

感谢大家的及时答复。我继续使用 W3C 验证器测试了上面的每个标签,在 div 或 span 中使用 rel 或 name 确实是无效的 X/HTML(我相信是严格的)。

Thx all for the prompt answers. I went ahead and tested each of the tags above with the W3C validator and it indeed is invalid X/HTML (strict, I believe) to use rel or name in divs or spans.

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