jquery制作的移动端购物车效果完整示例

2020-05-29 07:30:09易采站长站整理

<img src="shop/shouye.jpg" alt="">
<p>首页</p>
</li><li>
<img src="shop/fenlei.jpg" alt="">
<p>分类</p>
</li><li>
<img src="shop/shouye.jpg" alt="">
<p>吃饭吧</p>
</li><li>
<img src="shop/car.jpg" alt="">
<p>购物车</p>
</li><li>
<img src="shop/shouye.jpg" alt="">
<p>我的</p>
</li>
</ul>
</footer>
</body>
</html>
<script src="jquery.js"></script>
<script src="index.js"></script>

js

<script src=”jquery.js”></script>  文件自行下载 版本11

index.js:


$(function () {
$(".mrnus").click(function () {
shopAdd($(this));
che();
})
$(".add").click(function () {
shopAdd($(this));
che();
})
$(".checks").click(function(){
checked($(this));
che();
})
$("#quan").click(function() {
quan();
})
})
function shopAdd(obj) {
// console.log(obj)
if(obj.html() == "+"){
// alert("jia")
let num = parseInt(obj.prev().html());
num++;
obj.prev().html(num);
// 改变价格
// 判断是否选中
if (obj.parent().parent().parent().parent().parent().parent().parent().find(".checks").html() !=""){
let pricr = parseInt(obj.parent().prev().find(".mon").html());
// console.log(pricr);
let money = parseInt($("#money").html());
money += pricr;
// console.log(price)
$("#money").html(money);
}
} else if (obj.html() == "-"){
// alert("j")
let num = parseInt(obj.next().html());
num--;
if(num <= 0){
num = 0;
// return;
}
obj.next().html(num);
// 改变价格
// 判断是否选中
if (obj.parent().parent().parent().parent().parent().parent().parent().find(".checks").html() != "") {
let price2 = parseInt(obj.parent().prev().find(".mon").html());
// console.log(pricr);
let money = parseInt($("#money").html());
money -= price2;
// console.log(price)
$("#money").html(money);
}
}
}
// 选择
function checked(checks) {
// console.log(checks.html())
if (checks.html() == ""){
checks.css({"background":"red"})
checks.html("√");
money(checks);
}else{
checks.css("background","white")
checks.html("");
money(checks,1);
}
}
function money(obj,x){
// alert(obj)
let price = parseInt(obj.parent().parent().find(".mon").html());