首页
  • 问答
  • 教程
  • 书籍
  • IT新闻
  • Are single quotes valid in HTML/XHTML?

    Are single quotes valid in HTML? And more specifically: XHTML strict.

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

    Yes, single quotes are valid.

    From the XML spec:

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

    A source of confusion on this matter seems to come from this article,

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

    which seems to claim that single quotes are not valid in xhtml. However, since no specification is cited, and since the article also claims that lowercase names for attributes and elements are forbidden, the author may merely be expressing an editorial prohibition against using single quotes.


    According to the spec, both are valid :-)

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

    And the W3C-Validator accepts it as well.

    链接地址: http://www.djcxy.com/p/14606.html

    上一篇: 用jQuery创建新元素的首选方法

    下一篇: HTML / XHTML中的单引号是否有效?