在 XHTML 1.0 Strict 中,属性值是否需要用引号引起来?
在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据 XHTML 1.0 规范,它们必须始终被引用。
来自 HTML 4 规范,单引号属性是允许的。
上面链接的 xhtml 规范将该部分列为“与 HTML 4 的差异”,因此由于单引号没有明确禁止,我认为这意味着单引号也是允许的。
From the XHTML 1.0 spec, they must always be quoted.
From the HTML 4 spec, single quoted attributes are allowed.
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.
是的,所有属性必须加引号,并且属性可以使用单引号或双引号。只要保持一致——不要用单引号打开属性并用双引号关闭。另外,您应该在结束斜杠和自结束标记的最后一个属性之间留一个空格,以保持与旧浏览器的兼容性,如下所示:
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: