加入购物车数量的增减

-----------html---------------------
          < div class= "input-content">
             < input type = "text" name = "qty" id = "qty" maxlength = "12" value = "1" title = "Qty" class = "input-text qty" >
             < input type = "button" onclick = " var qty_el = document . getElementById ('qty'); var qty = qty_el . value ; if ( ! isNaN ( qty )) qty_el . value ++ ; return false ; " class = "qty-increase" >
             < input type = "button" onclick = " var qty_el = document . getElementById ('qty'); var qty = qty_el . value ; if ( ! isNaN ( qty ) & amp ; & amp ; qty > 0 ) qty_el . value -- ; return false ; " class = "qty-decrease" >
        </ div >
下面两个input是用来控制数量加减的
----------css---------------
.product-view .input-content  {
  1. floatleft;
  2. border1px solid #f1f1f1;
  3. padding3px 10px;
  4. width75px;
}
.product-options-bottom .add-to-cart .qty  {
  1. backgroundnone;
  2. border0;
  3. box-shadownone;
  4. color#777;
  5. font-family'titilliumweb';
  6. floatleft;
  7. font-size16px;
  8. height30px;
  9. line-height30px;
  10. padding0;
  11. text-alignleft;
  12. width30px !important;
  13. margin0;
}
.add-to-cart input.qty-increase  {
  1. bordermedium none;
  2. floatleft;
  3. height5px;
  4. margin9px 0 3px 6px;
  5. padding0;
  6. width10px;
  7. backgroundurl(../images/bg-qty.png) no-repeat 0 0;
  8. cursorpointer;
    1. font-size13px;
    2. line-height20px;
    3. vertical-alignmiddle;
    4. color#777;
}
.add-to-cart input.qty-decrease  {
  1. bordermedium none;
  2. floatleft;
  3. height5px;
  4. margin0 0 0 6px;
  5. padding0;
  6. width10px;
  7. backgroundurl(../images/bg-qty.png) no-repeat 0 100%;
  8. cursorpointer;
    1. font-size13px;
    2. line-height20px;
    3. vertical-alignmiddle;
    4. color#777;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,我可以为您提供一些关于实现这些功能的基本思路和代码示例。不过需要注意的是,这只是一个简单的示例,实际的购物网站需要考虑更多的功能和细节,还需要进行更严格的安全性和可靠性测试。 首先,我们需要一个 HTML 页面作为我们的购物网站的基础框架。以下是一个简单的示例 HTML 页面,包括导航栏、商品列表和购物车: ```html <!DOCTYPE html> <html> <head> <title>购物网站</title> <meta charset="utf-8"> <link rel="stylesheet" type="text/css" href="style.css"> <script type="text/javascript" src="script.js"></script> </head> <body> <header> <nav> <ul id="menu"> <li><a href="#">首页</a></li> <li class="submenu"><a href="#">全部商品分类</a> <ul> <li><a href="#">服装</a></li> <li><a href="#">鞋帽</a></li> <li><a href="#">数码</a></li> </ul> </li> <li><a href="#">我的订单</a></li> <li><a href="#">我的购物车</a> <span id="cart-count">(0)</span></li> </ul> </nav> </header> <main> <ul id="product-list"> <li><img src="product1.jpg"><h3>商品1</h3><p>价格:100元</p><button class="add-to-cart">加入购物车</button></li> <li><img src="product2.jpg"><h3>商品2</h3><p>价格:200元</p><button class="add-to-cart">加入购物车</button></li> <li><img src="product3.jpg"><h3>商品3</h3><p>价格:300元</p><button class="add-to-cart">加入购物车</button></li> </ul> </main> <footer> <p>版权所有 © 2021 购物网站</p> </footer> </body> </html> ``` 在这个 HTML 页面中,我们定义了一个导航栏和一个包含商品列表的主要部分。导航栏包含一个树形菜单,可以展开和收起子菜单。购物车部分包含一个当前购物车数量的计数器和一个可以增加和减少数量的按钮。 接下来,我们需要用 CSS 样式表来美化我们的购物网站。以下是一个简单的示例 CSS 样式表: ```css header { background-color: #f2f2f2; padding: 10px; box-shadow: 0px 5px 10px rgba(0, 0, 0, 0.1); } nav ul { list-style: none; margin: 0; padding: 0; } nav li { display: inline-block; position: relative; } nav a { display: block; padding: 10px; text-decoration: none; color: #666; } nav ul ul { position: absolute; top: 100%; left: 0; background-color: #fff; box-shadow: 0px 5px 10px rgba(0, 0, 0, 0.1); display: none; } nav li:hover > ul { display: block; } #cart-count { background-color: #f00; color: #fff; padding: 2px 5px; border-radius: 50%; margin-left: 5px; } .add-to-cart { background-color: #f00; color: #fff; padding: 5px 10px; border: none; border-radius: 5px; cursor: pointer; margin-top: 10px; } #product-list { list-style: none; margin: 0; padding: 0; } #product-list li { display: inline-block; margin: 10px; padding: 10px; background-color: #f2f2f2; box-shadow: 0px 5px 10px rgba(0, 0, 0, 0.1); text-align: center; } #product-list li img { width: 200px; height: 200px; } #product-list li h3 { margin: 10px 0; } #product-list li p { margin: 10px 0; } #product-list li button { display: block; margin: 10px auto 0; } ``` 在这个 CSS 样式表中,我们为导航栏、商品列表和购物车等元素定义了样式。我们使用了一些 CSS 技巧来实现树形菜单和添加购物车的功能。 最后,我们需要使用 JavaScript 来实现购物车增减和全部商品分类下的二级菜单。以下是一个简单的示例 JavaScript 脚本: ```javascript // 获取所有的子菜单 var submenus = document.querySelectorAll('.submenu > ul'); // 遍历所有子菜单,为每个子菜单添加事件处理程序 for (var i = 0; i < submenus.length; i++) { submenus[i].addEventListener('click', function(event) { event.stopPropagation(); }); } // 获取购物车数量计数器和增减按钮 var countEl = document.getElementById('cart-count'); var addButton = document.querySelectorAll('.add-to-cart'); // 初始化购物车数量为0 var count = 0; // 遍历所有的增减按钮,为每个按钮添加事件处理程序 for (var i = 0; i < addButton.length; i++) { addButton[i].addEventListener('click', function() { count++; countEl.innerText = '(' + count + ')'; }); } ``` 在这个 JavaScript 脚本中,我们先获取了所有的子菜单,并为每个子菜单添加了一个点击事件处理程序,以防止点击子菜单时导航栏关闭。然后,我们获取了购物车数量计数器和增减按钮,并为每个按钮添加了一个点击事件处理程序,以便增加和减少购物车数量。 综上所述,这是一个简单的 HTML、CSS 和 JavaScript 示例,演示了如何实现购物网站的导航栏、商品列表和购物车等基本功能。但是,对于一个实际的购物网站来说,还需要考虑更多的功能和细节,例如用户登录、支付、订单跟踪等等。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值