<分区>
当单击带有类“button”的“add.png”图像时,它会将项目添加到购物车并转换为“remove.png”当再次单击它时,它将从购物车中删除该项目并转换回其原始“添加.png"
这适用于 Jquery 1.7 及更低版本,但 .toggle() 功能已从较新版本的 Jquery 中删除。
期望的结果是执行完全相同的任务,但使用 .click() 而不是 .toggle()
<img class="button" data-product-id="Item1" src="add.png" />
<script>
$(".button").toggle(function(){
//first functon here
simpleCart.add({
name: $(this).attr("data-product-id"),
price: .99,
quantity: 1
});
//we set src of image with jquery
$(this).attr("src", "remove.png");
},function(){
//second function here
//simplecart remove function here, this isjust example, adjust with your code
simpleCart.add({
name: $(this).attr("data-product-id"),
price: .99,
quantity: -1
});
$(this).attr("src", "add.png");
});
</script>