功能分析:
1、实现单选和全选
2、实现商品数量的加减和输入,小计金额和总件数也跟着发生改变,以及判断是否选中
3、实现选中商品金额总计
4、 可以删除商品,删除商品后的总件数以及已选择件数,和总金额的改变
5、可以加入购物车,加入购物车后的总件数的改变,以及拥有相应的功能
1、HTML相关代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>小米购物车,打死不改</title>
<link rel="stylesheet" href="https://at.alicdn.com/t/font_2329460_legvgzs3jvm.css">
<script src="js/mi.js"></script>
<link rel="stylesheet" href="css/mi.css">
</head>
<body>
<div class="center">
<table>
<tbody class="tb">
<tr class="thead">
<td class="fist"><i class="iconfont icon-succ all"></i> 全选</td>
<td class="simg"></td>
<td class="shopName">商品名称</td>
<td class="price">单价</td>
<td class="number">数量</td>
<td class="count">小计</td>
<td class="op">操作</td>
</tr>
</tbody>
</table>
</div>
<div class="crta">
<div class="c-left">
<a href="#" class="back-shopping">继续购物</a>
<span class="cart-total">共<i class="c-number">3</i> 件商品,已选择
<i class="g-number">0</i>件
</span>
</div>
<div class="total-price">
<span>合计:<em>0</em>元</span>
<div class="noTip">请勾选需要结算的商品</div>
<a href="javascript:" class="close btn-disabled">去结算</a>
</div>
</div>
<div class="content">
<h2 class="shoptitle"><span class="title">买购物车中商品的人还买了</span></h2>
<div class="shop-all">
<ul class="shopList clearfix">
</ul>
</div>
</div>
</html>
2、css样式代码
* {
margin: 0;
padding: 0;
}
a {
text-decoration: none;
}
tr,
td {
box-sizing: border-box;
}
body {
background-color: #f5f5f5;
}
.center {
width: 1226px;
margin: 0 auto;
padding-top: 50px;
margin-top: 100px;
background-color: #fff;
border-top: 2px solid #ff6700;
}
table {
border-collapse: collapse;
}
.c {
width: 110px;
}
.simg {
width: 120px;
}
.icon-succ {
display: inline-block;
width: 18px;
height: 18px;
line-height: 18px;
border: 1px solid #e0e0e0;
margin-left: 24px;
margin-right: 20px;
background-color: #fff;
color: #fff;
font-size: 16px;
text-align: center;
vertical-align: middle;
position: relative;
top: -1px;
cursor: pointer;
}
/* 悬停 */
.icon-succ:hover {
color: #757575;
}
table .tb .btn {
background-color: #ff6700;
color: #fff;
}
.thead {
width: 1226px;
height: 70px;
color: #424242;
font-size: 16px;
}
.thead tr {
height: 70px;
}
.shopName {
width: 380px;
}
.number {
text-align: center;
width: 150px;
}
.price {
text-align: center;
width: 158px;
}
.count {
text-align: center;
width: 201px;
box-sizing: border-box;
}
.op {
text-align: center;
width: 80px;
}
/* tr边框 */
.tlist {
padding: 15px 26px 15px 0;
border-top: 1px solid #e0e0e0;
height: 117px;
box-sizing: border-box;
}
/*计数框 */
.nu {
border: 1px solid #e0e0e0;
height: 38px;
width: 100%;
display: flex;
text-align: center;
justify-content: space-between;
position: relative;
}
.nu .msg {
position: absolute;
width: 100%;
left: 0;
bottom: -24px;
font-size: 12px;
color: #b0b0b0;
display: none;
}
/* 加减 */
.nu span {
font-size: 12px;
width: 40px;
height: 38px;
font-weight: bold;
display: inline-block;
line-height: 40px;
}
.nu span:hover {
background-color: #e0e0ee;
transition: all 0.3s;
}
.numbers {
margin-right: 40px;
}
/* */
.shopNumber {
width: 72px;
height: 38px;
line-height: 38px;
padding: 0;
border-width: 0;
color: #424242;
font-size: 16px;
outline: none;
text-align: center;
}
.clear::after {
content: "";
display: block;
clear: both;
}
/* 文字说明 */
.titles {
font-size: 18px;
font-weight: 400;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
}
/* 删除 */
.ic {
color: #ff6700;
}
.icon-X- {
width: 24px;
height: 24px;
display: inline-block;
line-height: 24px;