单引号在 HTML 中有效吗?更具体地说:XHTML 严格。
<table width="100%">
<table width='100%'>
单引号在 HTML 中有效吗?更具体地说:XHTML 严格。
<table width="100%">
<table width='100%'>
是的,单引号是有效的。
从 XML 规范:
[10] AttValue ::= '"' ([^<&"] | Reference)* '"'
| "'" ([^<&'] | Reference)* "'"
关于这个问题的混淆来源似乎来自这篇文章,
http://www.javascriptkit.com/howto/xhtml_intro.shtml
这似乎声称单引号在 xhtml 中无效。然而,由于没有引用规范,并且由于文章还声称属性和元素的小写名称是被禁止的,所以作者可能只是在表达对使用单引号的编辑禁止。
根据规范,两者都是有效的:-)
[9] EntityValue ::= '"' ([^%&"] | PEReference | Reference)* '"'
| "'" ([^%&'] | PEReference | Reference)* "'"
[10] AttValue ::= '"' ([^<&"] | Reference)* '"'
| "'" ([^<&'] | Reference)* "'"
[11] SystemLiteral ::= ('"' [^"]* '"') | ("'" [^']* "'")
[12] PubidLiteral ::= '"' PubidChar* '"' | "'" (PubidChar - "'")* "'"
W3C-Validator 也接受它。