【发布时间】:2011-09-23 15:08:09
【问题描述】:
Attribute quotes are optional in HTML5.
引用它们的优点/缺点是什么?
id=example <!--quotes optional-->
href=http://example.com <!--quotes optional-->
class="example example-1" <!--quotes required due to space-->
href="http://example.com/p=47" <!--quotes required due to '=' sign-->
更新:根据答案增加了优势:
引用所有属性的优点:
- 所有编辑都能妥善处理
- 更一致
- 更好的可移植性(更容易更改文档类型)
- 更易于维护(尤其是如果属性可能变为空)
- 更容易“查找和替换”更改
- 更简洁的文档(如果您认为引号可以提高可读性)
- ?
省略可选引号的优点:
- 文件大小略微减小
- 更简洁的文档(如果您喜欢最少的文本)
- ?
【问题讨论】:
-
“更干净的文档”?呃,不这么认为。
-
我投票支持社区维基,因为它是主观的
-
请参阅mathiasbynens.be/notes/unquoted-attribute-values,了解有关在 HTML 和 CSS/JavaScript 中何时需要在属性值周围使用引号的确切规则。我还发了a tool that will tell you if a given attribute value can be used without quotes or not。
-
您可以使用单引号(撇号)代替双引号。这使得使用许多编程语言(Java 等)更容易。
-
这类问题我可以推荐vote4code.com :)
标签: html performance standards