为什么不应该使用 `'` 来转义单引号?
如 HTML 中的单引号何时变得如此流行? 和 属性中的 Jquery 嵌入引用,HTML 表示以下内容:
单引号字符 (') 在用于引用属性值时,还必须转义为
'
或'
(除 XHTML 文档外,不应转义为'
)当它出现在属性值本身中时。
为什么不应该使用'
?另外,使用 "
代替 "
安全吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
"
位于有效 HTML 的官方列表中4 个实体,但'
不是。来自 C.16。命名字符参考':
"
is on the official list of valid HTML 4 entities, but'
is not.From C.16. The Named Character Reference ':
"
在 HTML5 和 HTML4 中均有效。'
在 HTML5 中有效,但在 HTML4。然而,大多数浏览器无论如何都支持 HTML4 的'
。"
is valid in both HTML5 and HTML4.'
is valid in HTML5, but not HTML4. However, most browsers support'
for HTML4 anyway.'
不是 HTML 4 标准的一部分。不过,
"
是可以使用的。'
is not part of the HTML 4 standard."
is, though, so is fine to use.如果您需要编写语义正确的标记,即使在 HTML5 中,您也不能使用
'
来转义单引号。虽然,我可以想象你实际上指的是撇号而不是单引号。单引号 和 撇号在语义上并不相同,尽管它们可能看起来相同。
如果您需要 HTML4 支持,请使用
'
插入它。 (已编辑)在英式英语中,单引号的用法如下:
报价成对出现。您可以使用:
,我说。
以语义上正确的方式嵌套引号,将实际字符的替换推迟到渲染引擎。这种替换可能会受到 CSS 规则 的影响,例如
:关于语义正确标记的旧但似乎仍然相关的文章:EM 'n EN(和其他可疑字符)的麻烦< /a>.
(已编辑)这曾经是:
但是,正如 @James_pic 指出的那样,这不是直单引号,而是“单弯引号,对吧”。
If you need to write semantically correct mark-up, even in HTML5, you must not use
'
to escape single quotes. Although, I can imagine you actually meant apostrophe rather then single quote.single quotes and apostrophes are not the same, semantically, although they might look the same.
Use
'
to insert it if you need HTML4 support. (edited)In British English, single quotes are used like this:
Quotes come in pairs. You can use:
<p><q>He told me to <q>give it a try</q></q>, I said.<p>
to have nested quotes in a semantically correct way, deferring the substitution of the actual characters to the rendering engine. This substitution can then be affected by CSS rules, like:
An old but seemingly still relevant article about semantically correct mark-up: The Trouble With EM ’n EN (and Other Shady Characters).
(edited) This used to be:
But, as @James_pic pointed out, that is not the straight single quote, but the "Single curved quote, right".
如果你确实需要单引号、撇号,你可以使用
If you really need single quotes, apostrophes, you can use