【JavaScript】练习七

本文介绍了如何使用JavaScript和jQuery实现购物车功能,包括页面加载后的金额统计、全选、数量增减及商品删除。同时,详细展示了jQuery实现图片轮播的代码,包括自动切换、鼠标悬停暂停及导航点高亮效果。
摘要由CSDN通过智能技术生成

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

$(function(){
	// 全选
	$('#allCheckBox').click(function(){
		var v=$(this).prop('checked');
		$("[name='cartCheckBox']").prop('checked',v);
	});
	$("[alt='minus']").click(function(){
		var v = $(this).next().val();
		if(v==0){
			var one=confirm("不能再减少喽!你是要删除该商品吗?");
			if(one){
				$(this).parents("tr").prev().remove();
				$(this).parents("tr").remove();
			}
		}else{
			$(this).next().val(v-1);
		}
		cal();
	});
	
	// 加一
	$("[alt='add']").click(function(){
		var v = $(this).prev().val();
		$(this).prev().val(parseInt(v)+1);
		cal();
	});
	//删除当前
	$(".cart_td_8 a").click(function(){
		$(this).parents("tr").prev().remove();
		$(this).parents("tr").remove();
		cal();
	});
	
	//删除suoxuan
	$("#deleteAll").click(function(){
		$("[name='cartCheckBox']:checked").each(function(i,e){
			$(e).parents("tr").prev().remove();
			$(e).parents("tr").remove();
		})
	});
	
	cal();
	//计算总金额以及总积分
	function cal(){
		var total=0;
		var sumscore=0;
		$('.cart_td_4').each(function(i,e){
			var score = $(e).text();
			var price = $(e).next().text();
			var num = $(e).parent().find('.num_input').val();
			var all = parseInt(price)*parseInt(num);
			$(e).parent().children('.cart_td_7').text(all);
			total+=all;
			sumscore+=parseInt(score)*parseInt(num);
		});
		$("#total").text(total);
		$("#integral").text(sumscore);
	}
})

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、付费专栏及课程。

余额充值