Javascript 为什么jquery函数不能在模态中工作?
我有在电子商务应用程序中添加到购物车的jquery代码。 这里的问题是,当我在索引页面上单击“添加到购物车”时,它工作正常。项目成功地移动到购物车 但当我按下“快速查看”按钮时,将打开一个包含产品详细信息的模式。 在模态上,我有相同的按钮,单击该按钮,项目不会移动到购物车 以下是我的开放模式代码Javascript 为什么jquery函数不能在模态中工作?,javascript,php,jquery,modal-dialog,shopping-cart,Javascript,Php,Jquery,Modal Dialog,Shopping Cart,我有在电子商务应用程序中添加到购物车的jquery代码。 这里的问题是,当我在索引页面上单击“添加到购物车”时,它工作正常。项目成功地移动到购物车 但当我按下“快速查看”按钮时,将打开一个包含产品详细信息的模式。 在模态上,我有相同的按钮,单击该按钮,项目不会移动到购物车 以下是我的开放模式代码 <a class="add_bag" data-id="<?=$row_category[0];?>" data-name="<?=$row_category[3];?>
<a class="add_bag" data-id="<?=$row_category[0];?>" data-name="<?=$row_category[3];?>" data-summary="<?=$row_category[3];?>" data-price="<?=$row_category[6];?>" data-quantity="1" data-image="<?=$row_category[13];?>" ><i class="fa fa-shopping-cart"></i>Add to bag</a>
你有索引页上提到的脚本吗是的,我有脚本。我在最后。所以你们的产品并没有进入购物车的索引页?是的。它的工作在索引页。但在索引页面上点击快速查看我打开了模态。在该模式下,我将添加到购物车按钮。所以,点击项目应该移动到购物车,但它没有。这意味着给定的jquery不起作用。您是否可以在“添加到购物车”jquery函数中添加警报,并在单击“添加到购物车”时确保它在那里?您是否有索引页上提到的脚本?是的,我有脚本。我在最后。所以你们的产品并没有进入购物车的索引页?是的。它的工作在索引页。但在索引页面上点击快速查看我打开了模态。在该模式下,我将添加到购物车按钮。所以,点击项目应该移动到购物车,但它没有。这意味着给定的jquery不起作用。您可以在add to cart jquery函数中添加警报,并在单击add to cart时确保其存在吗
$(function () {
var goToCartIcon = function($addTocartBtn){
var $cartIcon = $(".shopping_bag_btn");
var $image = $('<img width="30px" height="30px" src="' + $addTocartBtn.data("image") + '"/>').css({"position": "absolute", "z-index": "999"});
$addTocartBtn.prepend($image);
var position = $cartIcon.position();
$image.animate({
top: 0,
right: 0
}, 500 , "linear", function() {
$image.remove();
});
}
$('.add_bag').myCart({
classCartIcon: 'shopping_bag_btn',
classCartBadge: 'my-cart-badge',
classProductQuantity: 'my-product-quantity',
classProductRemove: 'my-product-remove',
classCheckoutCart: 'my-cart-checkout',
affixCartIcon: true,
showCheckoutModal: true,
clickOnAddToCart: function($addTocart){
goToCartIcon($addTocart);
},
clickOnCartIcon: function($cartIcon, products, totalPrice, totalQuantity) {
console.log("cart icon clicked", $cartIcon, products, totalPrice, totalQuantity);
},
checkoutCart: function(products, totalPrice, totalQuantity) {
console.log("checking out", products, totalPrice, totalQuantity);
},
getDiscountPrice: function(products, totalPrice, totalQuantity) {
console.log("calculating discount", products, totalPrice, totalQuantity);
return totalPrice;
}
});
});