如何通过 HTML 代码编写双引号

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15135769/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 05:58:54  来源:igfitidea点击:

How to Code Double Quotes via HTML Codes

htmlasciihtml-entities

提问by H. Ferrence

In HTML, What is the preferred way to specify html codes like ", and what is the major differences? For example:

在 HTML 中,指定 html 代码的首选方式是"什么,主要区别是什么?例如:

&quot;    <!-- friendly code -->
&#34;     <!-- numerical code -->
&#x22;    <!-- hex code -->

Which one should I use and would it ever be an issue if one of these gets deprecated?

我应该使用哪一个,如果其中一个被弃用,它会成为问题吗?

回答by James Donnelly

There really aren't any differences.

真的没有任何区别。

&quot;is processed as &#34;which is the decimal equivalent of &x22;which is the ISO 8859-1 equivalent of ".

&quot;被处理为&#34;的十进制等效值&x22;是 ISO 8859-1 等效值的".

The only reason you may be against using &quot;is because it was mistakenly omitted from the HTML 3.2 specification.

您可能反对使用的唯一原因&quot;是它被错误地从 HTML 3.2 规范中省略了

Otherwise it all boils down to personal preference.

否则一切都归结为个人喜好。

回答by Andy

Google recommend that you don't use any of them, source.

谷歌建议你不要使用它们中的任何一个,来源。

There is no need to use entity references like &mdash, &rdquo, or &#x263a, assuming the same encoding (UTF-8) is used for files and editors as well as among teams.

假设文件和编辑器以及团队之间使用相同的编码 (UTF-8),则无需使用诸如&mdash,&rdquo或 之 类的实体引用&#x263a

Is there a reason you can't simply use "?

有什么理由不能简单地使用"吗?

回答by Jukka K. Korpela

There is no difference, in browsers that you can find in the wild these days (that is, excluding things like Netscape 1 that you might find in a museum). There is no reason to suspect that any of them would be deprecated ever, especially since they are all valid in XML, in HTML 4.01, and in HTML5 CR.

没有什么区别,你现在可以在野外找到的浏览器(也就是说,不包括你可能在博物馆中找到的 Netscape 1 之类的东西)。没有理由怀疑它们中的任何一个会被弃用,特别是因为它们在 XML、HTML 4.01 和 HTML5 CR 中都是有效的。

There is no reason to use any of them, as opposite to using the Ascii quotation mark (") directly, except in the very special case where you have an attribute value enclosed in such marks and you would like to use the mark inside the value (e.g., title="Hello &quot;world&quot;"), and even then, there are almost always better options (like title='Hello "word"'or title="Hello “word”".

没有理由使用它们中的任何一个,这与直接使用 Ascii 引号 (") 相反,除非在非常特殊的情况下,您的属性值包含在此类标记中,并且您希望在值内使用该标记(例如,title="Hello &quot;world&quot;"),即使如此,几乎总是有更好的选择(例如title='Hello "word"'title="Hello “word”".

If you want to use “smart” quotation marks instead, then it's a different question, and none of the constructs has anything to do with them. Some people expect notations like &quot;to produce “smart” quotes, but it is easy to see that they don't; the notations unambiguously denote the Ascii quote ("), as used in computer languages.

如果您想改用“智能”引号,那么这是一个不同的问题,并且没有任何构造与它们有关。有些人期望符号&quot;能产生“聪明”的引语,但很容易看出他们没有;这些符号明确表示计算机语言中使用的 Ascii 引号 (")。