当点击某个图像时,我想使用jQuery
将一些内容添加到其他页面。我有一个名为product.php
的通用页面,在此页面上添加的内容取决于在主页(home.php)
上点击的图像。在product.php
我想添加一个div的内容,其编号为#product
。如何在点击链接时将内容添加到页面,然后使用jQuery重定向到该页面?
但是当图片被点击时,它会重定向到product.php
的未修改页面。在想要的内容被加载后有没有办法重定向到product.php
页面?
$('.product img').click(function() {
// it gives the right index
var index = $(".product img").index(this);
// it works well
var myProduct = 'snippet-product'+ (index + 1)+'.php';
$("#product").load(myProduct);
// it redirects to the 'product.php' without the new content
window.location.href = 'product.php';
return false;
});
你可以附加一些参数的URL。类似于window.location.href ='product.php'+'?param' – lharby
是否要将内容加载到#product div并导航到另一页? – lharby
是的我想将内容加载到product.php上特定的#product div中,然后我想将其重定向到product.php页面并能够看到加载的内容 –