Why should I use & instead of &?

帅比萌擦擦* 提交于 2020-01-02 01:12:10

问题


why should I use & instead of & when writing HTML for my site?

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?

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.

Hopefully someone can clear my mind?

Thanks!


回答1:


From 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.
  • &lt; (<) - Required because otherwise a browser could misinterpret it as the beginning of a tag
  • &gt; (>) - Required because otherwise a browser could misinterpret it as the ending of a tag
  • &quot; (") - Required only within attributes value surrender by quote sign

See here for a full list of all HTML character entities - https://dev.w3.org/html5/html-author/charref




回答2:


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



来源:https://stackoverflow.com/questions/35367945/why-should-i-use-amp-instead-of

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!