-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path购物车页面.html
426 lines (415 loc) · 15.5 KB
/
购物车页面.html
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script src="http://how2j.cn/study/js/jquery/2.0.0/jquery.min.js"></script>
<link href="http://how2j.cn/study/css/bootstrap/3.3.6/bootstrap.min.css" rel="stylesheet">
<script src="http://how2j.cn/study/js/bootstrap/3.3.6/bootstrap.min.js"></script>
</head>
<style>
body {
font-size: 12px;
font-family: arial;
}
div.cartDiv {
min-width: 1013px;
margin: 10px auto;
color: black;
max-width: 1350px;
}
div.cartTitle button {
background-color: #aaaaaa;
border: 1px solid #AAAAAA;
color: white;
width: 53px;
height: 25px;
border-radius: 2px;
text-align: center;
}
div.cartTitle span.cartTitlePrice {
color: #C40000;
font-size: 14px;
font-weight: bold;
margin-left: 5px;
margin-right: 3px;
}
div.cartFoot {
background-color: #e5e5e5;
line-height: 50px;
margin: 20px 0px;
color: black;
padding-left: 20px;
}
div.cartFoot button {
background-color: #AAAAAA;
border: 0px solid #AAAAAA;
color: white;
width: 120px;
height: 50px;
font-size: 20px;
text-align: center;
}
img.
, img.selectAllItem {
cursor: pointer;
}
span.cartSumNumber {
color: #C40000;
font-size: 16px;
font-weight: bold;
}
span.cartSumPrice {
font-size: 20px;
font-weight: bold;
color: #C40000;
}
/*************************************************/
table.cartProductTable {
width: 1080px;
font-size: 12px;
}
tr.cartProductItemTR {
border: 1px solid #CCCCCC;
}
tr.cartProductItemTR td {
padding: 20px 17px;
}
table.cartProductTable th {
font-weight: normal;
color: #3c3c3c;
padding: 20px 20px;
}
img.cartProductImg {
padding: 1px;
border: 1px solid #EEEEEE;
width: 80px;
height: 80px;
}
table.cartProductTable th.selectAndImage {
width: 100px;
}
div.cartProductLinkOutDiv {
position: relative;
height: 40px;
}
a.cartProductLink {
color: #3c3c3c;
}
a.cartProductLink:hover {
color: #C40000;
text-decoration: none;
}
div.cartProductLinkInnerDiv {
position: absolute;
bottom: 0;
height: 20px;
}
span.cartProductItemOringalPrice {
text-decoration: line-through;
color: #9c9c9c;
display: block;
font-weight: bold;
font-size: 14px;
}
span.cartProductItemPromotionPrice {
font-family: arial;
font-size: 14px;
font-weight: bold;
color: #C40000;
}
div.cartProductChangeNumberDiv {
border: 1px solid #e5e5e5;
width: 80px;
}
div.cartProductChangeNumberDiv a {
width: 14px;
display: inline-block;
text-align: center;
color: black;
text-decoration: none;
}
div.cartProductChangeNumberDiv input {
border: 1px solid #AAAAAA;
width: 42px;
display: inline-block;
outline: none;
}
span.cartProductItemSmallSumPrice {
font-family: arial;
font-size: 14px;
font-weight: bold;
color: #C40000;
}
img.cartProductItemIfSelected, img.selectAllItem{
cursor: pointer;
}
</style>
<body>
<div class="cartDiv">
<div class="cartTitle pull-right">
<span>已选商品 (不含运费)</span>
<span class="cartTitlePrice">¥0.00</span>
<button type="button" class="createOrderButton" style="background-color: rgb(170, 170, 170);" disabled="disabled">结 算</button>
</div>
<div class="cartDiv">
<div class="cartProductList">
<table class="cartProductTable">
<thead>
<tr>
<th class="selectAndImage">
<img src="http://how2j.cn/tmall/img/site/cartNotSelected.png" class="selectAllItem" selectit="false">
全选
</th>
<th>商品信息</th>
<th>单价</th>
<th>数量</th>
<th width="120px">金额</th>
<th class="operation">操作</th>
</tr>
</thead>
<tbody>
<tr class="cartProductItemTR" oiid="936">
<td>
<img src="http://how2j.cn/tmall/img/site/cartNotSelected.png" class="cartProductItemIfSelected" oiid="936" selectit="false">
<a href="#nowhere" style="display:none"><img src="http://how2j.cn/tmall/img/site/cartSelected.png"></a>
<img width="40px" src="http://how2j.cn/tmall/img/productSingle_middle/3665.jpg" class="cartProductImg">
</td>
<td>
<div class="cartProductLinkOutDiv">
<a class="cartProductLink" href="#nowhere">美国iRobot扫地机器人吸尘器全自动家用智能扫地机650 天猫电器城</a>
<div class="cartProductLinkInnerDiv">
<img title="支持信用卡支付" src="http://how2j.cn/tmall/img/site/creditcard.png">
<img title="消费者保障服务,承诺7天退货" src="http://how2j.cn/tmall/img/site/7day.png">
<img title="消费者保障服务,承诺如实描述" src="http://how2j.cn/tmall/img/site/promise.png">
</div>
</div>
</td>
<td>
<span class="cartProductItemOringalPrice">¥7580.0</span>
<span class="cartProductItemPromotionPrice">¥5306.0</span>
</td>
<td>
<div class="cartProductChangeNumberDiv">
<span pid="365" class="hidden orderItemStock ">75</span>
<span pid="365" class="hidden orderItemPromotePrice ">5306.0</span>
<a href="#nowhere" class="numberMinus" pid="365">-</a>
<input value="1" autocomplete="off" class="orderItemNumberSetting" oiid="936" pid="365">
<a href="#nowhere" class="numberPlus" pid="365" stock="75">+</a>
</div>
</td>
<td>
<span pid="365" oiid="936" class="cartProductItemSmallSumPrice">¥5306.00</span>
</td>
<td>
<a href="#nowhere" oiid="936" class="deleteOrderItem">删除</a>
</td>
</tr>
<tr class="cartProductItemTR" oiid="935">
<td>
<img src="http://how2j.cn/tmall/img/site/cartNotSelected.png" class="cartProductItemIfSelected" oiid="935" selectit="false">
<a href="#nowhere" style="display:none"><img src="http://how2j.cn/tmall/img/site/cartSelected.png"></a>
<img width="40px" src="http://how2j.cn/tmall/img/productSingle_middle/8510.jpg" class="cartProductImg">
</td>
<td>
<div class="cartProductLinkOutDiv">
<a class="cartProductLink" href="#nowhere">阔腿裤三件套装女夏装2016新款大码雪纺时尚休闲气质棉麻九分裤潮</a>
<div class="cartProductLinkInnerDiv">
<img title="支持信用卡支付" src="http://how2j.cn/tmall/img/site/creditcard.png">
<img title="消费者保障服务,承诺7天退货" src="http://how2j.cn/tmall/img/site/7day.png">
<img title="消费者保障服务,承诺如实描述" src="http://how2j.cn/tmall/img/site/promise.png">
</div>
</div>
</td>
<td>
<span class="cartProductItemOringalPrice">¥235.0</span>
<span class="cartProductItemPromotionPrice">¥152.75</span>
</td>
<td>
<div class="cartProductChangeNumberDiv">
<span pid="809" class="hidden orderItemStock ">17</span>
<span pid="809" class="hidden orderItemPromotePrice ">152.75</span>
<a href="#nowhere" class="numberMinus" pid="809">-</a>
<input value="1" autocomplete="off" class="orderItemNumberSetting" oiid="935" pid="809">
<a href="#nowhere" class="numberPlus" pid="809" stock="17">+</a>
</div>
</td>
<td>
<span pid="809" oiid="935" class="cartProductItemSmallSumPrice">
¥152.75
</span>
</td>
<td>
<a href="#nowhere" oiid="935" class="deleteOrderItem">删除</a>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="cartFoot">
<img src="http://how2j.cn/tmall/img/site/cartNotSelected.png" class="selectAllItem" selectIt="false" />
<span>全选</span>
<div class="pull-right">
<span>已选商品<span class="cartSumNumber">0</span>件</span>
<span>合计 (不含运费): </span>
<span class="cartSumPrice">¥0.00</span>
<button class="createOrderButton" style="background-color: rgb(170, 170, 170);" disabled="disabled">结 算</button>
</div>
</div>
</div>
<script>
//千进制格式化数字函数
function formatMoney(num){
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + num + '.' + cents);
}
//按钮同步函数
function syncCreateOrderButton() {
var selectAny = false;
$('.cartProductItemIfSelected').each(function() {
if("selectit" == $(this).attr('selectit')) {
selectAny = true;
}
});
if(selectAny) {
$('button.createOrderButton').css("background-color","#C40000");
$('button.createOrderButton').removeAttr("disabled");
}
else {
$('button.createOrderButton').css("background-color","#AAAAAA");
$('button.createOrderButton').attr("disabled","disabled");
}
}
//同步全选状态
function syncSelect() {
var selectAll = true;
$(".cartProductItemIfSelected").each(function() {
if("false" == $(this).attr("selectit")) {
selectAll = false;
}
});
if(selectAll) {
$("img.selectAllItem").attr("src","http://how2j.cn/tmall/img/site/cartSelected.png");
}
else {
$("img.selectAllItem").attr("src","http://how2j.cn/tmall/img/site/cartNotSelected.png");
}
}
//显示被选中的商品总数,以及总价格
function calcCartSumPriceAndNumber() {
var sum = 0;
var totalNumber = 0;
$("img.cartProductItemIfSelected[selectit='selectit']").each(function() {
var oiid1 = $(this).attr("oiid");
var price = $(".cartProductItemSmallSumPrice[oiid="+oiid1+"]").text();
price = price.replace(/,/g,"");
price = price.replace(/¥/g,"");
sum += new Number(price);
var num =$(".orderItemNumberSetting[oiid="+oiid1+"]").val();
totalNumber += new Number(num);
});
$("span.cartSumPrice").html("¥"+formatMoney(sum));
$("span.cartTitlePrice").html("¥"+formatMoney(sum));
$("span.cartSumNumber").html(totalNumber);
}
//根据商品数量,商品价格,同步小计价格,接着调用calcCartSumPriceAndNumber()函数同步商品总数和总价格
function syncPrice(pid,num,price) {
$(".orderItemNumberSetting[pid="+pid+"]").val(num);
var cartProductItemSmallSumPrice = formatMoney(num * price);
$(".cartProductItemSmallSumPrice[pid="+pid+"]").html("¥"+cartProductItemSmallSumPrice);
calcCartSumPriceAndNumber();
}
//响应选中一种商品的JS
$("img.cartProductItemIfSelected").click(function() {
var selectit = $(this).attr("selectit");
if("selectit" == selectit) {
$(this).attr("src","http://how2j.cn/tmall/img/site/cartNotSelected.png");
$(this).attr("selectit","false");
$(this).parents("tr.cartProductItemTR").css("background-color","#fff");
}
else {
$(this).attr("src","http://how2j.cn/tmall/img/site/cartSelected.png");
$(this).attr("selectit","selectit")
$(this).parents("tr.cartProductItemTR").css("background-color","#FFF8E1");
}
syncSelect(); //同步全选状态
syncCreateOrderButton(); //同步按钮状态
calcCartSumPriceAndNumber(); //同步显示选中商品的个数和总价格
});
//商品全选
$("img.selectAllItem").click(function() {
var selectit = $(this).attr("selectit");
if(selectit == "selectit") {
$("img.selectAllItem").attr("src","http://how2j.cn/tmall/img/site/cartNotSelected.png");
$("img.selectAllItem").attr("selectit","false");
$("img.cartProductItemIfSelected").each(function() {
$(this).attr("src","http://how2j.cn/tmall/img/site/cartNotSelected.png");
$(this).attr("selectit","false");
$(this).parents("tr.cartProductItemTR").css("background-color","#fff");
});
}
else {
$("img.selectAllItem").attr("src","http://how2j.cn/tmall/img/site/cartSelected.png");
$("img.selectAllItem").attr("selectit","selectit");
$("img.cartProductItemIfSelected").each(function() {
$(this).attr("src","http://how2j.cn/tmall/img/site/cartSelected.png");
$(this).attr("selectit","selectit");
$(this).parents("tr.cartProductItemTR").css("background-color","#fff8e1");
});
}
syncCreateOrderButton(); //按钮同步
calcCartSumPriceAndNumber(); //同步价格和数量
});
//增加和减少数量
$(".numberPlus").click(function() {
var pid = $(this).attr("pid");
var stock = $("span.orderItemStock[pid="+pid+"]").text();
var price = $("span.orderItemPromotePrice[pid ="+pid+"]").text();
var num = $(".orderItemNumberSetting[pid ="+pid+"]").val();
num++;
if(num > stock) {
num = stock;
}
syncPrice(pid,num,price);
});
$(".numberMinus").click(function() {
var pid = $(this).attr("pid");
var stock = $("span.orderItemStock[pid="+pid+"]").text();
var price = $("span.orderItemPromotePrice[pid ="+pid+"]").text();
var num = $(".orderItemNumberSetting[pid ="+pid+"]").val();
num--;
if(num <= 0) {
num = 1;
}
syncPrice(pid,num,price);
});
//直接在输入框里面修改商品数量
$(".orderItemNumberSetting").keyup(function() {
var pid = $(this).attr("pid");
var stock= $("span.orderItemStock[pid="+pid+"]").text();
var price= $("span.orderItemPromotePrice[pid="+pid+"]").text();
var num= $(".orderItemNumberSetting[pid="+pid+"]").val();
num = parseInt(num);
if(isNaN(num))
num = 1;
if(num <= 0)
num = 1;
if(num >stock)
num = stock;
syncPrice(pid,num,price);
});
</script>
</body>
</html>