2015-06-02 185 views
0

这里是我的htmlhref属性打破元素

<a class="button special" href="http://secure.hostgator.com/~affiliat/cgi-bin/affiliates/clickthru.cgi?id=vpspricing&page=http://www.hostgator.com/vps-hosting">Select</a> 

一些CSS - 我不认为这是重要的,但无论如何,包括。

background-color: #449403; 
box-shadow: none !important; 
color: #FFF !important; 
margin-left: 2px; 

我已经固定下来到是因为http://www.google.com各种其他的URL在href值将工作和。我的一个元素出现在检查元素中,但它没有出现在GUI中,我不知道为什么。那里有一个我应该逃跑的角色吗?

+1

'&page'应该是'& page'。 –

+0

你能在小提琴中重现吗? – andi

+1

在此处运行良好http://jsfiddle.net/741pn99m/ – Arbel

回答

2

尴尬,但我adblocker挡住的链接...

1

尝试使用URL编码查询字符串。您可以使用encodeURI JavaScript函数

1

该URL应该是HTML编码的,查询字符串值应该是URL编码的。

&应HTML编码为&amp;,和:/中的值应该URL编码为%3A%2F

href="http://secure.hostgator.com/~affiliat/cgi-bin/affiliates/clickthru.cgi?id=vpspricing&amp;page=http%3A%2F%2Fwww.hostgator.com%2Fvps-hosting" 

击穿:第一值vpspricinghttp://www.hostgator.com/vps-hosting是URL编码成vpspricing(没有变化)和http%3A%2F%2Fwww.hostgator.com%2Fvps-hosting,以便您可以将它们放入URL中。然后,您会对整个网址进行HTML编码,以便您可以将其放入HTML代码中的属性中。在这种情况下,只有需要进行HTML编码的&字符。

相关问题