是否可以在HTML属性中的值周围使用单引号? [英] Is it acceptable to use single quotes around values in HTML attributes?

查看:640
本文介绍了是否可以在HTML属性中的值周围使用单引号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

HTML单引号a“问题"

可以使用围绕html属性值的单引号,例如:

Is it acceptable to use single quotes around html attribute values like this:

<span class='classname'>Hi</span>

而不是像这样的双引号:

Instead of double quotes like this:

<span class="classname">Hi</span>

谁定义什么是好的? W3C?

Who defines what's okay? W3C?

推荐答案

是的,可以接受。它在浏览器中可用,并且受规范允许。

Yes, that's acceptable. It works in browsers, and it's allowed by the specifications.

HTML5规范说:


在HTML语法中,属性可以指定四种不同的方法:

In the HTML syntax, attributes can be specified in four different ways:


  1. 空属性语法

  2. 无引号的属性值语法

  3. 单引号属性值语法

  4. 双引号属性值语法

  1. empty attribute syntax
  2. unquoted attribute-value syntax
  3. single-quoted attribute-value syntax
  4. double-quoted attribute-value syntax


HTML4 spec 说:


默认情况下,SGML要求所有
属性值使用
双引号(ASCII
十进制34)或单引号
(ASCII十进制39)。单个引号标记
可以包含在属性
值中,该值由
双引号标记分隔,反之亦然。

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). Single quote marks can be included within the attribute value when the value is delimited by double quote marks, and vice versa.

这篇关于是否可以在HTML属性中的值周围使用单引号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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