当按下按钮时,会出现两个功能。第一个功能是将“item1”添加到购物车,第二个功能是将按钮图像从“add.png”更改为“minus.png”。将按钮切换到“minus.png”后,如果再次按下按钮,则期望的结果是从购物车中删除该项目,并且图像转换为其原始“add.png”。 http://simplecartjs.org/documentation/simplecart-item-remove
按钮示例:http: //jsfiddle.net/9kmun19z/
<img id="button" onclick="addbeat(event);changeImage()" name="item1" src="add.png"/>
<script>
function addbeat(event) {
simpleCart.add({
name: event.target.name,
price: .99
});
}
function changeImage() {
var image = document.getElementById('button');
if (image.src.match("minus")) {
image.src = "add.png";
} else {
image.src = "minus.png";
simpleCart.item.remove();({
name: event.target.name,
price: .99
});
}
}
</script>