你引用HTML5属性吗? [英] Do you quote HTML5 attributes?
问题描述
引用它们的优点/缺点是什么?
id = example<! - quotes optional - >
href = http://example.com<! - quotes optional - >
class =示例示例-1<! - 由于空间需要的引号 - >
href =http://example.com/p=47<! - 由于'='符号所需的引号 - >
更新:根据答案增加优势: 优点忽略可选引号: 我赞成始终使用引号。 它看起来更清晰,更一致 这更容易o维护 - 您可以在不破坏引号的情况下编辑值,因为缺少引号。
引用所有属性的优势:
$ b
Attribute quotes are optional in HTML5.
What are the pros/cons to quoting them?
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-->
Update: Added advantages based on the answers:
Advantages to quoting all attributes:
- all editors can deal with it properly
- more consistent
- better portability (easier to change doctype)
- easier to maintain (esp. if attributes might become empty)
- easier to 'find and replace' changes
- cleaner doc (if you think quotes improve readability)
- ?
Advantages to omitting optional quotes:
- slightly reduced filesize
- cleaner doc (if you prefer minimal text)
- ?
I'm in favour of always using quotes.
It looks way cleaner and more consistent
All editors can deal with it properly
It's easier to maintain - you can edit values without breaking them because quotes are missing.
The few bytes you save in document size by dropping quotes where they are not needed are not worth mentioning (unless maybe you're Google's home page).
这篇关于你引用HTML5属性吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!