简体   繁体   English

我应该在 href="" 中使用 & 还是在 HTML4 和 HTML5 中使用 & 就足够了?

[英]Should I use & in href="" or & is enough in HTML4 and HTML5?

Should I use &我应该使用& in href="" or & is enough in HTML4 and HTML5?在 HTML4 和 HTML5 中使用href=""&就足够了吗?

The most of browser not have problem with this but how it should be done?大多数浏览器都没有这个问题,但是应该怎么做呢?

<a href="?param1=1&param2=2">Call()</a>

Or或者

<a href="&quest;param1=1&amp;param2=2">Call()</a>

&amp; is correct.是正确的。 The bare ampersand generally works because if a browser sees an & that isn't followed by a valid entity reference, it passes it through, but there's no reason you should count on this behavior in code, especially if you can't guarantee the contents of the thing following the & .裸 & 符号通常有效,因为如果浏览器看到&后面没有有效的实体引用,它会通过它,但是没有理由你应该在代码中指望这种行为,特别是如果你不能保证内容&后面的东西。 In particular, it's forbidden for &foo;特别是对于&foo;是禁止的。 to appear where "foo" is an alphanumeric string that isn't valid named character (this is called an "ambiguous ampersand" in HTML5), and it's obviously undesirable for &foo;出现在“foo”是一个无效的命名字符的字母数字字符串的位置(这在 HTML5 中被称为“不明确的 & 符号”),这对于&foo;显然是不可取的。 to appear where "foo" is a valid named character, because it will be parsed as that character.出现在“foo”有效命名字符的位置,因为它将被解析为该字符。

See the relevant spec requirements:https://html.spec.whatwg.org/multipage/syntax.html#attributes-2查看相关规范要求:https ://html.spec.whatwg.org/multipage/syntax.html#attributes-2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM