gpt4 book ai didi

html - 在 中使用 "&"

转载 作者:行者123 更新时间:2023-11-28 04:32:11 25 4
gpt4 key购买 nike

目前,我有:

<a href="process.php?action=start&pid=1">Start Process</a>

但是,我通过 W3 HTML 验证器 ( https://validator.w3.org ) 运行这段代码,结果如下:

& did not start a character reference. (& probably should have been escaped as &amp;.)

是否有另一种正确的方法将“&”放入 <a></a> 中?标记,还是我应该保持原样?

最佳答案

处理 URL 中的符号 (&) 在 Web Design Group 中有解释。的 Common Validator Problems page :

Ampersands (&'s) in URLs

Another common error occurs when including a URL which contains an ampersand ("&"):

<!-- This is invalid! --> <a href="foo.cgi?chapter=1&section=2&copy=3&lang=en">...</a>

This example generates an error for "unknown entity section" because the "&" is assumed to begin an entity reference. Browsers often recover safely from this kind of error, but real problems do occur in some cases. In this example, many browsers correctly convert &copy=3 to ©=3, which may cause the link to fail. Since &lang; is the HTML entity for the left-pointing angle bracket, some browsers also convert &lang=en to 〈=en. And one old browser even finds the entity &sect;, converting &section=2 to §ion=2.

To avoid problems with both validators and browsers, always use &amp; in place of & when writing URLs in HTML:

<a href="foo.cgi?chapter=1&amp;section=2&amp;copy=3&amp;lang=en">...</a>

Note that replacing & with &amp; is only done when writing the URL in HTML, where "&" is a special character (along with "<" and ">"). When writing the same URL in a plain text email message or in the location bar of your browser, you would use "&" and not "&amp;". With HTML, the browser translates "&amp;" to "&" so the Web server would only see "&" and not "&amp;" in the query string of the request.

关于html - 在 <a></a> 中使用 "&",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30960944/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com