让 sEncodedHref
代表一个 HttpUtility.HtmlAttributeEncode(..)
的字符串。
生成的 html 之间是否存在任何功能差异:
String.Format(@"<span class='blue' src='{0}'>", sEncodedHref);
对比生成的 html 是这样的:
String.Format(@"<span class=""blue"" src=""{0}"">", sEncodedHref);
我的印象是单引号变体既不受支持又不太“安全”,但是我无法提供支持该论点的理由。
最佳答案
没有功能上的区别。 Quoting the W3C on SGML and HMTL :
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). Single quote marks can be included within the attribute value when the value is delimited by double quote marks, and vice versa.
...
In certain cases, authors may specify the value of an attribute without any quotation marks. The attribute value may only contain letters (a-z and A-Z), digits (0-9), hyphens (ASCII decimal 45), periods (ASCII decimal 46), underscores (ASCII decimal 95), and colons (ASCII decimal 58). We recommend using quotation marks even when it is possible to eliminate them.
关于c# - 单引号和双引号 html 属性之间的功能区别是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3338969/