简体   繁体   English

在href属性中转义html是否有效?

[英]Is it valid to escape html in a href attribute?

Assuming I have the following link: 假设我有以下链接:

<a href='http://google.com/bla'>http://google.com/bla</a>

Is this one also valid? 这也有效吗?

<a href='http:&#x2F;&#x2F;google.com/bla'>http://google.com/bla</a>

It works in Firefox, but I'm not sure if this is standardized behavior. 它可以在Firefox中运行,但是我不确定这是否是标准行为。 I hope the question isn't super dumb! 我希望这个问题不是超级傻瓜!

Yes, it is perfectly valid to do that. 是的,这样做是完全有效的。 In fact, the ampersand ( & ) character must be escaped into &amp; 实际上, &字符必须转义为&amp; in order to be valid HTML, even inside the href attribute (and all attributes for that matter). 为了成为有效的HTML,甚至在href属性(以及与此相关的所有属性)中也是如此。

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

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