在HTML属性中使用单引号是否可以接受? [重复]

时间:2022-10-28 15:39:01

This question already has an answer here:

这个问题在这里已有答案:

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

是否可以在html属性值周围使用单引号,如下所示:

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

Instead of double quotes like this:

而不是像这样的双引号:

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

Who defines what's okay? W3C?

谁定义什么是好的? W3C?

3 个解决方案

#1


15  

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

是的,这是可以接受的。它适用于浏览器,并且规范允许。

The HTML5 spec says:

HTML5规范说:

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

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

  1. empty attribute syntax
  2. 空属性语法

  3. unquoted attribute-value syntax
  4. 不带引号的属性值语法

  5. single-quoted attribute-value syntax
  6. 单引号属性值语法

  7. double-quoted attribute-value syntax
  8. 双引号属性值语法

The HTML4 spec says:

HTML4规范说:

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.

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

#2


0  

Single quotes are and have always been completely kosher, according to the W3 specification. It's a markup/code style choice, nothing more.

根据W3规范,单引号一直是犹太洁食。这是标记/代码风格的选择,仅此而已。

#3


0  

Yes, the W3C publishes HTML standards.

是的,W3C发布了HTML标准。

They also provide a validator at http://validator.w3.org/

他们还在http://validator.w3.org/上提供了验证器

the validator is ok with both for XHTML 1.0 Strict.

对于XHTML 1.0 Strict,验证器都可以。

There is several HTML standards, so whether it’s "acceptable" entirely depends on which you're using. Furthermore collaborative projects may have a coding style which defines to use one or the other. Using " is de-facto standard, even if the HTML standard may allow ' as well.

有几种HTML标准,因此它是否“可接受”完全取决于您使用的是什么。此外,协作项目可以具有定义为使用一个或另一个的编码样式。使用“是事实上的标准,即使HTML标准可能允许”。

#1


15  

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

是的,这是可以接受的。它适用于浏览器,并且规范允许。

The HTML5 spec says:

HTML5规范说:

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

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

  1. empty attribute syntax
  2. 空属性语法

  3. unquoted attribute-value syntax
  4. 不带引号的属性值语法

  5. single-quoted attribute-value syntax
  6. 单引号属性值语法

  7. double-quoted attribute-value syntax
  8. 双引号属性值语法

The HTML4 spec says:

HTML4规范说:

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.

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

#2


0  

Single quotes are and have always been completely kosher, according to the W3 specification. It's a markup/code style choice, nothing more.

根据W3规范,单引号一直是犹太洁食。这是标记/代码风格的选择,仅此而已。

#3


0  

Yes, the W3C publishes HTML standards.

是的,W3C发布了HTML标准。

They also provide a validator at http://validator.w3.org/

他们还在http://validator.w3.org/上提供了验证器

the validator is ok with both for XHTML 1.0 Strict.

对于XHTML 1.0 Strict,验证器都可以。

There is several HTML standards, so whether it’s "acceptable" entirely depends on which you're using. Furthermore collaborative projects may have a coding style which defines to use one or the other. Using " is de-facto standard, even if the HTML standard may allow ' as well.

有几种HTML标准,因此它是否“可接受”完全取决于您使用的是什么。此外,协作项目可以具有定义为使用一个或另一个的编码样式。使用“是事实上的标准,即使HTML标准可能允许”。