29

单引号在 HTML 中有效吗?更具体地说:XHTML 严格。

<table width="100%">
<table width='100%'>
4

3 回答 3

23

是的,单引号是有效的。

从 XML 规范:

[10]   AttValue  ::= '"' ([^<&"] | Reference)* '"'
                  |  "'" ([^<&'] | Reference)* "'"
于 2010-02-05T21:11:27.093 回答
6

关于这个问题的混淆来源似乎来自这篇文章,

http://www.javascriptkit.com/howto/xhtml_intro.shtml

这似乎声称单引号在 xhtml 中无效。然而,由于没有引用规范,并且由于文章还声称属性和元素的小写名称是被禁止的,所以作者可能只是在表达对使用单引号的编辑禁止。

于 2010-04-11T00:16:05.243 回答
4

根据规范,两者都是有效的:-)

[9]    EntityValue    ::=    '"' ([^%&"] | PEReference | Reference)* '"'  
   |  "'" ([^%&'] | PEReference | Reference)* "'" 
[10]    AttValue    ::=    '"' ([^<&"] | Reference)* '"'  
   |  "'" ([^<&'] | Reference)* "'" 
[11]    SystemLiteral    ::=    ('"' [^"]* '"') | ("'" [^']* "'")  
[12]    PubidLiteral    ::=    '"' PubidChar* '"' | "'" (PubidChar - "'")* "'"

W3C-Validator 也接受它。

于 2010-02-05T21:13:20.117 回答