In XHTML 1.0 Strict do attribute values need to be surrounded with quotes?

丶灬走出姿态 提交于 2019-12-02 01:22:45

问题


In XHTML 1.0 Strict do attribute values need to be surrounded with quotes?

Example:

<input type="text" id="username"/>

And if so according to the standard can single quotes be used and possible mixed with double quotes?

Example:

<input type='text' id="username"/>

回答1:


From the XHTML 1.0 spec, they must always be quoted.

All attribute values must be quoted, even those which appear to be numeric.


From the HTML 4 spec, single quoted attributes are allowed.

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)

The xhtml spec linked above lists the section as 'Differences from HTML 4', so since single quotes are not specifically disallowed, I think that means single quotes are allowed as well.




回答2:


Yes, all attributes must be quoted, and yes, attributes can use single or double quotes. Just be consistant—don't open an attribute with a single quote and close with a double quote. And also, you should leave a space between the closing slash and the last attribute of self-closing tags, to keep compatibility with old browsers, as so:

<input type="text" id="username" />


来源:https://stackoverflow.com/questions/5398993/in-xhtml-1-0-strict-do-attribute-values-need-to-be-surrounded-with-quotes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!