你引用 HTML5 属性吗? [英] Do you quote HTML5 attributes?

查看:37
本文介绍了你引用 HTML5 属性吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

属性引号在 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:

引用所有属性的优点:

  • 所有编辑都能妥善处理
  • 更加一致
  • 更好的可移植性(更容易更改文档类型)
  • 更易于维护(特别是如果属性可能变为空)
  • 更容易查找和替换"更改
  • 更简洁的文档(如果您认为引号可以提高可读性)
  • ?

省略可选引号的优点:

  • 稍微减小了文件大小
  • 更简洁的文档(如果您喜欢最少的文字)
  • ?

推荐答案

我赞成总是使用引号.

  • 看起来方式更干净、更一致

所有编辑都能妥善处理

更容易维护 - 您可以编辑值而不会因为缺少引号而破坏它们.

It's easier to maintain - you can edit values without breaking them because quotes are missing.

通过在不需要的地方删除引号来节省文档大小的几个字节是不值得一提的(除非您可能是 Google 的主页).

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆