JS代码写简单购物车

本文通过JavaScript、HTML和CSS实现了一个简单的购物车功能。主要内容包括CSS样式的设计,HTML结构的搭建,以及核心的JS代码实现购物车的添加、删除和计算总价等操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

实现效果:

CSS样式: 

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        table {
            width: 50%;
            margin: 1.5rem auto;
            border-collapse: collapse;
            border: .1rem solid gray;
        }

        th {
            background: yellow;
            height: 1rem;
            border: .1rem solid gray;
        }

        tr {
            height: 1rem;
            text-align: center;
        }

        td {
            border: .1rem solid gray;
        }
    </style>
</head>

 HTML代码:

<body>
    <table>
        <tr>
            <th>商品名称</th>
            <th>数量</th>
            <th>单价</th>
            <th>小计</th>
            <th>操作</th>
        </tr>
        <tr>
            <td>西瓜</td>
            <td>
                <button>-</button>
                <span class
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值