[英]Toggle issue with shopping cart jPayPalCart.js
我在使用jPayPalCart.js切換myCart div時遇到困難。 我的購物車運轉正常。 當我加載頁面時,我可以通過單擊右上方的購物車來切換購物車。 我在myCart代碼中添加了另一個按鈕,它顯示“關閉”並關閉myCart div。
但是,當我向購物車中添加商品時,(僅演示頁面上的第一個商品實際上添加了商品)單擊購物車圖標時不再觸發此功能。 我在瀏覽器的控制台中看不到任何錯誤。
只有刷新頁面后,它才能再次起作用。 如何做到這一點,而不必刷新頁面?
非常感謝有人幫我解決這個問題,這已經使我瘋狂了兩天。
$(document).ready(function () {
$(".menu").activeMenu();
$("#myCart").hide();
// Create a basic cart
$("#myCart").PayPalCart({
business: 'mypaypal@myemail.com',
notifyURL: 'http://www.diditwork.com/payment.aspx',
virtual: false, //set to true where you are selling virtual items such as downloads
quantityupdate: true, //set to false if you want to disable quantity updates in the cart
currency: 'CAD', //set to your trading currency - see PayPal for valid options
currencysign: '$', //set the currency symbol
minicartid: 'minicart', //element to show the number of items and net value
persitdays: 0 //set to -1 for cookie-less cart for single page of products,
// 0 (default) persits for the session,
// x (number of days) the basket will persits between visits
});
$(".cartImg").click(function () {
alert("your hitting it");
$("#myCart").toggle();
});
$(".closeCart").click(function () {
alert("your hitting it");
$("#myCart").hide();
});
});
仍然環顧四周,我找到了解決方案。 通過使用.live(),修改click函數似乎可以正常工作。 如果您查看API文檔,則將看到詳細信息,但基本上,購物車是“動態”更新的,從而更改了對象的屬性。 .live()“刷新”此狀態,從而可以在腳本中識別該對象。
$(".cartImg").live("click", function () {
alert("your hitting it");
$("#myCart").toggle();
});
$(".closeCart").live("click", function () {
alert("your hitting it");
$("#myCart").hide();
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.