c# - 单引号和双引号 html 属性之间的功能区别是什么?

标签 c# html

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/

相关文章:

html - 如何做一个绝对定位(溢出:hidden) container's absolutely positioned children show outside of their parent's area?

c# - Entity Framework 按类更改数据库物理位置

c# - 如何从文件中读取特殊字符?

c# - 不同的值成员,相同的控件

jquery - 仅使用 css3 删除元素时应用 css3 动画

javascript - 加载生成内容中的图像时触发事件

javascript - 将点击转换为 onmouseover javascript

c# - 从函数调用按钮 OnClick

c# - 依赖注入(inject)的学习原理,适用于这种情况?

javascript - Angular Js http GET 响应显示在控制台日志中,但我无法显示 ng-view