好吧,我有一个通过PHP加载到另一个html页面的html页面(没错,所以它是一个PHP页面,不管)。加载的页面是超链接列表。我需要更改href属性以使超链接相对于它们所指向的存储图像的位置。当我加载包含超链接的页面时,链接是相对于Web主机服务器的,而不是实际托管页面的服务器。使用jQuery更改悬停时的href属性
财产以后这样的:
<div #screenshots)
<p><a href="image1.htm">Image1</a></p>
<p><a href="image2.htm">Image2</a></p>
<p><a href="image3.htm">Image3</a></p>
<p><a href="image4.htm">Image4</a></p>
<p><a href="image5.htm">Image5</a></p>
</div>
当我将鼠标放在链接时,状态栏显示的参考为“http://webHostServer.com/image1.htm”。如果我点击它,我会得到一个404错误。我需要在href当我在它的鼠标来改变这样的事情:“http://www.actualImageHostServerIPaddress/image1.htm”
我看着this如需协助,并与下面的jQuery代码就出来了,但没有它的一些原因,工作原理:
$(document).ready(function(){
$("button").click(function() {
$("#screenshots a").addClass('ss');
});
$(".ss").each(function()
{
$(this).data("oldHref", $(this).attr("href"));
orig = $(this).attr("href");
over = "http://208.167.244.33/208.167.244.33/";
$(this).hover(function() {
$(this).attr("href", $(this).attr("href").replace(orig, over+orig));
}, function() {
$(this).attr("href", $(this).data("oldHref"));
});
});
当我点击按钮时,它不会将类添加到锚标记,所以当我将它悬停在它们上面时,没有任何变化。这里的任何帮助都会很棒。
图像是否存储在每台服务器上相同的相对路径? – 2010-04-06 04:18:21
我会解决真正的问题。 – 2010-04-06 04:18:49
难道只是我,还是你“通过绕月亮前往莫斯科”?我的意思是,为什么不加载链接时更改链接并完成它?或者更好的是,在服务器上更改它们? – 2010-04-06 04:19:57