2010-02-05 31 views
23

單引號是否在HTML中有效?更具體地說:XHTML嚴格。單引號在HTML/XHTML中有效嗎?

<table width="100%"> 
<table width='100%'> 
+2

如果再次懷疑,您可以通過http://validator.w3.org/檢查您的文檔。 – Leonidas 2010-02-05 21:18:56

回答

20

是的,單引號是有效的。

從XML規範:

[10] AttValue ::= '"' ([^<&"] | Reference)* '"' 
        | "'" ([^<&'] | Reference)* "'" 
3

按照spec,都是有效的:-)

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

和W3C驗證器接受它。

4

在這個問題上混亂的根源似乎來自這篇文章中,

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

這似乎宣稱單引號是不是在XHTML有效。然而,由於沒有引用規範,並且由於文章還聲稱屬性和元素的小寫名稱是禁止的,所以作者可能僅僅表達禁止使用單引號的編輯禁止。

相關問題