Javascript 我为什么要使用 & 代替 &?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35367945/
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
Why should I use & instead of &?
提问by Il Magnus
why should I use &
instead of &
when writing HTML for my site?
为什么我应该在为我的网站编写 HTML 时使用&
而不是&
?
Where can I find a list of other symbols that I should be encoding? (the bar / too, right?)
在哪里可以找到我应该编码的其他符号列表?(酒吧/也是,对吧?)
What problems could I have if I paste the symbol right as it is into the html?
如果我将符号按原样粘贴到 html 中,我会遇到什么问题?
The thing is, I have a few affiliate links and I'm worried that, if I write them with the & in some cases, for some reasons, because of the specific browser or device... that the info in the url wouldn't be passed correctly.
问题是,我有一些附属链接,我担心,如果我在某些情况下使用 & 编写它们,出于某些原因,由于特定的浏览器或设备...... url 中的信息不会t 被正确传递。
Hopefully someone can clear my mind?
希望有人能清除我的思绪?
Thanks!
谢谢!
回答by Jon
From https://developer.mozilla.org/en-US/docs/Glossary/Entity
来自https://developer.mozilla.org/en-US/docs/Glossary/Entity
HTML has a set of four reserved characters that must be represented as entities. All other characters can be represented with entities as needed, but it is not mandatory. These are the entities used for those four reserved characters :
&
(&) - Required, so that a browser does not misinterpret it as the beginning of an entity.<
(<) - Required because otherwise a browser could misinterpret it as the beginning of a tag>
(>) - Required because otherwise a browser could misinterpret it as the ending of a tag"
(") - Required only within attributes value surrender by quote sign
HTML 有一组必须表示为实体的四个保留字符。所有其他字符都可以根据需要用实体表示,但这不是强制性的。这些是用于这四个保留字符的实体:
&
(&) - 必需,以便浏览器不会将其误解为实体的开头。<
(<) - 必需,否则浏览器可能会将其误解为标签的开头>
(>) - 必需,否则浏览器可能会将其误解为标签的结尾"
(") - 仅在属性值中需要用引号引起来
See here for a full list of all HTML character entities - https://dev.w3.org/html5/html-author/charref
有关所有 HTML 字符实体的完整列表,请参见此处 - https://dev.w3.org/html5/html-author/charref
回答by Muhammad Asad Ali Amjad
The character '&' is reserved word which has special purpose. That's why you have to use it in specific way.
字符“&”是有特殊用途的保留字。这就是为什么你必须以特定的方式使用它。
Here you can find the HTML Entities. http://www.w3schools.com/html/html_entities.asp
在这里您可以找到 HTML 实体。http://www.w3schools.com/html/html_entities.asp