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);
})