文章目錄
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>购物车</title>
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.2.min.js"></script>
<script>
$(function(){
var dd={
flag:true,
}
//全选事件
$("#checkall").click(function(){
if(dd.flag){
$(".java input[type=checkbox]").each(function(){
var di=$(this);
if(di.attr("checked")!=true){
di.attr("checked",true);
}

})
totil();
dd.flag=false;
}else{
$(".java input[type=checkbox]").each(function(){
var di=$(this);

if($(di).attr("checked")=="checked"){
$(di).attr("checked",false);
}

})
totil();
dd.flag=true;
}
})
//商品选中事件
$(".eee").click(function(){
totil();

})

})
//结算总价
function totil(){
var str=0;
$(".java input:checkbox:checked").each(function(){
var rc=$(this).parent().parent().find(".dania");
str+=parseInt(rc.text());

})
$("#totil").html(str+".00元");

}
//减号按纽
function reduce(ddd){
//alert($(ddd).val());
var this2=$(ddd);
var val=$(ddd).parent().find(".ttt").val();
if(val<1){
alert("数量不能小于0");
return;}
var val2=parseInt(val)-1;
$(ddd).parent().find(".ttt").val(val2);
var dj=$(ddd).parent().parent().find(".dania").attr("dj");
butoi(this2,val2,dj);
}
//加号按钮
function add(ddd){
//alert($(ddd).val());

var this2=$(ddd);
var val=$(ddd).parent().find(".ttt").val();
//alert(val);

var val2=parseInt(val)+1;
$(ddd).parent().find(".ttt").val(val2);

var dj=$(ddd).parent().parent().find(".dania").attr("dj");

butoi(this2,val2,dj);
}
//商品总价
function butoi(t,val,danjia){
var sum=val*danjia;
t.parent().parent().find(".dania").html(sum+".00元");
totil();
}
</script>

</head>
<style>
*{ margin:0px; padding:0px;}
ul li { list-style:none; float:left; margin-right:20px;}
.java{ margin-left:500px; margin-top:20px; border:#9C0 solid 1px; float:left;}
.javas{margin-left:500px; margin-top:20px; border:#9C0 solid 1px;float:left;}
.dania{ color:#F00;}
</style>

<body>
<div class="shop">
<div class="java">
<ul>
<li><input type="checkbox" class="eee"></li>
<li><input type="button" value="-" onClick="reduce(this)"><input type="text" style="width:30px;" value="0" class="ttt"><input type="button" value="+" onClick="add(this)"></li>
<li class="dania" dj="9">0.00元</li>
</ul>

</div>
<div style="clear:both"></div>
<div class="java">
<ul>
<li><input type="checkbox" class="eee"></li>
<li><input type="button" value="-" onClick="reduce(this)"><input type="text" style="width:30px;" value="0" class="ttt"><input type="button" value="+" onClick="add(this)"></li>
<li class="dania" dj="10">0.00元</li>
</ul>
</div>
</div>
<div style="clear:both"></div>
<div class="javas"><input type="checkbox" id="checkall">全选&nbsp;&nbsp;&nbsp;&nbsp;总价<span id="totil">0.00元</span></div>
</body>
</html>

文章目錄