當點擊某個圖像時,我想使用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頁面並能夠看到加載的內容 –