模仿淘宝购物车

本文介绍如何通过JavaScript实现类似淘宝购物车的功能,包括商品选择、数量增减等效果。通过示例代码展示了关键的样式设计和JavaScript实现逻辑。
摘要由CSDN通过智能技术生成

效果图
在这里插入图片描述

样式

*{
    margin: 0;
    padding: 0;
}
.main{
    width: 850px;
    height: 780px;
    margin: 10px auto;
}
p{
    font-size: 13px;
    margin: 20px 0px;
}
li{
    list-style: none;
}
a {
    text-decoration: none;
    color: #1991db;
}
a:hover{
    color: blue;
    text-decoration: underline !important;
}
.main_menu{
    width: 820px;
    height: 23px;
}
.main_menu span{
    display: block;
    height: 23px;
    line-height: 23px;
    float: left;
}
.main_menu .s1{
    width:3px;
    height: 23px;
    background: url("images/taobao_bg.png") no-repeat -12px -92px;
}
.main_menu .s2{
    width:146px;
    height: 23px;
    font-size: 14px;
    text-align: center;
    font-weight: bold;
    color: white;
    cursor: pointer;
    background-color: #ff6600;
}
.main_menu .s3{
    width:15px;
    height: 23px;
    background: url("images/taobao_bg.png") no-repeat;
    background-color: #ff6600;
}
.main_menu .s4{
    width:146px;
    height: 23px;
    font-size: 14px;
    text-align: center;
    font-weight: bold;
    cursor: pointer;
    background-color: #e4e4e4;
    color: #333333;
}
.main_menu .s5{
    width:15px;
    height: 23px;
    background: url("images/taobao_bg.png") no-repeat;
    background-color: #e4e4e4;
}
.main_menu .s6{
    width:3px;
    height: 23px;
    background: url("images/taobao_bg.png") no-repeat -12px -138px;
}
.main_center{
    width: 850px;
    height: 630px;
    margin-top: 10px;
}

.main_center  td{
    text-align: center;
    font-size: 13px;
}
.main_center .tr1 .tt1,.tr4 .td1{
    width: 49px;
}
.main_center .tr1 .tt2,.tr4 .td2{
    width: 349px;
}
.main_center .tr1 .tt3,.tr4 .td3{
    width: 79px;
}
.main_center .tr1 .tt4,.tr4 .td4{
    width: 79px;
}
.main_center .tr1 .tt5,.tr4 .td5{
    width: 99px;
}
.main_center .tr1 .tt6,.tr4 .td6{
    width: 50px;
}
.main_center .tr1 .tt7,.tr4 .td7{
    width: 79px;
}
.tr2 {
    width: 850px;
    height: 3px;
    background-color: #a7cbff;
}
.tr3{
    height: 35px;
    padding: 0px;
}
.tr3 td{
    text-align: left;
    padding-top: 15px;
    height: 20px;
    line-height: 0px;
}
.tr3 td img {
    vertical-align: middle;
    margin-left: 4px;
}
.tr4 td{
    height: 92px;
    background-color: #e2f2ff;
}
.td2{
    height: 92px;
    line-height: 92px;
}
.td2 .ul1{
    padding-top: 20px;
}
.td2 .ul2{
    padding-top: 10px;
}
.td2 ul{
    width: 250px;
    height: 60px;
    float: right;
    margin-top: 6px;
    margin-right: 8px;
}
.td2 ul li{
    text-align: left;
    line-height: 20px;
}
.td2 ul li img,.td2 img{
    vertical-align: middle;
}
.td3{
    font-weight: bold;
}
.td5 div {
    width: 74px;
    height: 26px;
    line-height: 26px;
    margin: 0 auto;
}
.td5 div .bn1,.td5 div .bn2{
    width: 14px;
    height: 12px;
    line-height: 10px;
    text-align: center;
    border: 1px solid #ccc;
    background-color: white;
    outline: none;
}
.td5 div input{
    width: 32px;
    outline: none;
    text-align: center;
}
.td6{
    font-weight: bold;
    color: #fe6400;
}
.tr5 td,.tr6 td,.tr7 td{
    text-align: right;
}
.tr5 span,tr6,span{
    font-size: 15px;
    font-weight: bold;
    color: #fe6400;
}
.tr5 td{
    height: 20px;
    padding-top: 5px;
    padding-right: 8px;
}
.tr6 td{
    height: 20px;
    padding-top: 15px;
    padding-right: 8px;
}
.tr7 td{
    height: 20px;
    padding-top: 5px;
    padding-right: 8px;
}
.tr6 td input{
    width: 110px;
    height: 26px;
    background-color: #e4e4e4;
    color: #130101;
    border: 1px solid #a5a5a5;
    border-radius: 4px;
    letter-spacing: 2px;
    outline: none;
    cursor: pointer;
}
.tr7 td input{
    width: 95p
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值