JavaScript作业7

1、实现购物车
具体功能,1)页面加载成功后,页面的金额,总金额统计完成
2)实现 全选
3)点击按钮实现 ± 1
4)删除一行
5)删除所选的多行

$(function (){
    $("#allCheckBox").click(function (){
        var v = $(this).prop("checked");
        $("[name ='cartCheckBox']").prop("checked", v);
    });
    cal();
    function cal(){
        var summoney = 0;
        var sumscore = 0;
        $(".cart_td_4").each(function (i,e){
            var score = $(e).text();
            var price = $(e).next().text();
            var num = $(e).next().next().children(".num_input").val();
            var all = parseInt(price)*parseInt(num);
            $(e).parent().children(".cart_td_7").text(all);
            summoney += all;
            sumscore += parseInt(num)*parseInt(score);
        });
        $("#total").text(summoney);
        $("#integral").text(sumscore);
    }
    $("[alt='minus']").click(function (){
        var v = $(this).next().val();
        if (v==1){
            var an = confirm("不能再减少了,您想要删除商品吗?")
            if (an){
                $(this).parents("tr").prev().remove();
                $(this).parents("tr").remove()
            }
        }
        else {
            v--;
            $(this).next().val(v);
        }
        cal();
    })
    $("[alt='add']").click(function (){
        var v = $(this).prev().val();
            v++;
            $(this).prev().val(v);
        cal();
    })
    $(".cart_td_8 a").click(function (){
        $(this).parents("tr").prev().remove();
        $(this).parents("tr").remove()
        cal();
    })
    $("[alt='delete']").click(function (){
        $("[name='cartCheckBox']:checked").each(function (i,e){
            $(e).parents("tr").prev().remove();
            $(e).parents("tr").remove();
        })
        cal();
    })
    $("#tianjia").click(function (){
        var v = $("#product1").clone(true);
        var s = $("#product1").prev().clone(true);
        $("table tr:last").before(s);
        $("table tr:last").before(v);
        cal();
    })
});

在这里插入图片描述

2、jQuery实现图片轮播

$(function(){
	 	 $("div img").eq(0).show();
	 	 $("div img").not(":first").hide();
	 	 $("ul li").eq(0).children("span").addClass("a_hover").removeClass("a_nomal");
	 	 $("ul li").mouseover(function(){
	 	 	clearInterval(timer);
	 	 	var index =  $(this).index();
	 	 	showImg(index);
	 	 	i=index;
	 	 }).mouseout(function(){
	 	 	timer = setInterval(fun01,1000);
	 	 });
	 	 function showImg(index){
	 	   var $img = $("div img").eq(index);
	 	   $img.show();
	 	   $("div img").not($img).hide();
	 	   var $li = $("ul li").eq(index);
	 	   $li.children("span").addClass("a_hover").removeClass("a_nomal");
	 	   $("ul li").not($li).children("span").removeClass("a_hover").addClass("a_nomal");
	 	 }
	 	 var i=0;
	 	 function fun01(){
	 	 	showImg(i);
	 	 	i++;
	 	 	if(i==3){
	 	 		i=0;
	 	 	}
	 	 }
	 	 var timer = setInterval(fun01,1000);
	 })
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值