在 XHTML 1.0 Strict 中,属性值是否需要用引号引起来?

发布于 2024-10-25 16:51:01 字数 234 浏览 5 评论 0原文

在 XHTML 1.0 Strict 中,属性值是否需要用引号引起来?

示例:

<input type="text" id="username"/>

如果根据标准,可以使用单引号并可以与双引号混合吗?

例子:

<input type='text' id="username"/>

In XHTML 1.0 Strict do attribute values need to be surrounded with quotes?

Example:

<input type="text" id="username"/>

And if so according to the standard can single quotes be used and possible mixed with double quotes?

Example:

<input type='text' id="username"/>

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

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

发布评论

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

评论(2

祁梦 2024-11-01 16:51:01

根据 XHTML 1.0 规范,它们必须始终被引用。

所有属性值都必须加引号,即使是那些看似数字的属性值。


来自 HTML 4 规范,单引号属性是允许的。

默认情况下,SGML 要求所有属性值都使用双引号(ASCII 十进制 34)或单引号(ASCII 十进制 39)分隔

上面链接的 xhtml 规范将该部分列为“与 HTML 4 的差异”,因此由于单引号没有明确禁止,我认为这意味着单引号也是允许的。

From the XHTML 1.0 spec, they must always be quoted.

All attribute values must be quoted, even those which appear to be numeric.


From the HTML 4 spec, single quoted attributes are allowed.

By default, SGML requires that all attribute values be delimited using either double quotation marks (ASCII decimal 34) or single quotation marks (ASCII decimal 39)

The xhtml spec linked above lists the section as 'Differences from HTML 4', so since single quotes are not specifically disallowed, I think that means single quotes are allowed as well.

审判长 2024-11-01 16:51:01

是的,所有属性必须加引号,并且属性可以使用单引号或双引号。只要保持一致——不要用单引号打开属性并用双引号关闭。另外,您应该在结束斜杠和自结束标记的最后一个属性之间留一个空格,以保持与旧浏览器的兼容性,如下所示:

<input type="text" id="username" />

Yes, all attributes must be quoted, and yes, attributes can use single or double quotes. Just be consistant—don't open an attribute with a single quote and close with a double quote. And also, you should leave a space between the closing slash and the last attribute of self-closing tags, to keep compatibility with old browsers, as so:

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