pc端 添加购物车示例
添加到购物车列表及相关商品推荐. <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<!--<script type="text/javascript" src="js/tool.js"></script>-->
<style type="text/css">
*{margin: 0;padding: 0;}
ul{list-style: none;}
a{text-decoration: none;}
.box{
width: 1200px;
border: 1px solid;
margin: 50px auto 0;
}
.box ul{
overflow: hidden;
}
.box ul li{
width: 260px;
height: 100px;
font-size: 12px;
float: left;
margin-right: 53px;
margin-bottom: 15px;
}
.box .product a img{
float: left;
width: 98px;
height: 98px;
border: 1px solid #ccc;
margin-right: 10px;
}
.box .product .txt{
float: left;
width: 150px;
height: 36px;
line-height: 18px;
overflow: hidden;
}
.box .product .price{
float: left;
width: 150px;
color: #d91f20;
font-size: 14px;
margin-top: 5px;
overflow: hidden;
}
.box .product .add_to_cart{
float: left;
width: 105px;
height: 30px;
border: 1px solid #ccc;
margin-top: 8px;
text-align: center;
line-height: 30px;
}
.header{
width: 1200px;
/*height: 100px;*/
border: 1px solid #ccc;
margin: 0 auto;
}
.header .title{
display: flex;
justify-content: space-around;
height: 30px;
line-height: 30px;
border: 1px solid #ccc;
background: #f3f3f3;
}
.header .cart_list_box{
max-height: 306px;
overflow: auto;
}
.header .cart_list{
border: 1px solid #ccc;
display: flex;
justify-content: space-between;
border-bottom: none;
}
.header .cart_list li{
float: left;
height: 50px;
width: 200px;
font-size: 14px;
line-height: 50px;
text-align: center;
overflow: hidden;
background: #fff4e8;
}
.header .cart_list li .img{
width: 50px;
height: 50px;
}
.product_total{
width: 1200px;
margin: 0 auto;
overflow: hidden;
outline: 1px solid #ccc;
}
.product_total .fr{
float: right;
width: 280px;
height: 50px;
}
.product_total .fr p{
float: left;
line-height: 50px;
color: #ccc;
font-size: 12px;
}
.product_total .fr .calc{
float: right;
width: 110px;
height: 50px;
background: #e64346;
color: #fff;
font-weight: bold;
text-align: center;
line-height: 50px;
font-size: 18px;
}
.product_total .fr p #total{
color: orange;
font-size: 22px;
}
.product_total .fr p i{
font-size: 20px;
color: orange;
font-style: normal;
}
.product_total .fl #removeAll{
float: left;
margin-left: 500px;
margin-top: 4px;
width: 110px;
height: 40px;
background: #fff8f8;
border: 1px solid #ffdfdf;
color: #999;
text-align: center;
line-height: 40px;
font-size: 16px;
}
</style>
</head>
<body>
<div class="header">
<ul class="title">
<li>编号</li>
<li>图片</li>
<li>标题</li>
<li>数量</li>
<li>单价</li>
<li>操作</li>
</ul>
<div class="cart_list_box"> </div>
</div>
<div class="product_total">
<div class="fl">
<button id="removeAll">清空购物车</button>
</div>
<div class="fr">
<p>合计:<i>¥</i><span id="total">00.00</span></p>
<button class="calc">去结算</button>
</div>
</div> <div class="box">
<h3>购买了该商品的用户还购买了</h3>
<ul class="con"> </ul>
</div>
<ul class="conModel">
<li style="display: none">
<div class="id" style="display:none">1</div>
<a href=""><img class="img" src="data:images/01.jpg"></a>
<p class="txt">益达(Extra)木糖醇无糖口香糖冰凉薄荷70粒98单瓶装</p>
<span class="price">¥13.90</span>
<a href="javascript:void(0)" class="add_to_cart">加入购物车</a>
</li>
</ul>
<script src="jquery-3.2.1.min.js"></script>
<script>
var json = [
{"id":"1","img":"images/01.jpg","txt":"益达(Extra)木糖醇无糖口香糖冰凉薄荷70粒98单瓶装","price":"¥13.90"},
{"id":"2","img":"images/02.jpg","txt":"益达(Extra)尊享护齿56g*3瓶京东定制装(草本精华+冰","price":"¥24.90"},
{"id":"3","img":"images/03.jpg","txt":"绿箭(DOUBLEMINT)无糖薄荷糖冰柠薄荷味35粒23.8g","price":"¥7.50"},
{"id":"4","img":"images/04.jpg","txt":"益达(Extra)木糖醇无糖口香糖香浓蜜瓜40粒56g单瓶装","price":"¥8.80"},
{"id":"5","img":"images/05.jpg","txt":"益达(Extra)无糖口香糖沁凉薄荷12片32g单盒装","price":"¥5.50"},
{"id":"6","img":"images/06.jpg","txt":"益达木糖醇无糖口香糖瓶装56g/瓶 益达口香糖 休闲零食","price":"¥8.80"},
{"id":"7","img":"images/07.jpg","txt":"益达木糖醇无糖口香糖瓶装56g/瓶*9口味组合休闲零食","price":"¥75.60"},
{"id":"8","img":"images/08.jpg","txt":"益达 无糖口香糖70粒摇一摇四口味合装 赠益达西瓜味24","price":"¥52.90"}
];
var parent = $(".con",$(".box")[0])[0];
for(var i = 0,len = json.length; i < len; i++){
var clone = $("li",$(".conModel")[0])[0].cloneNode(true);
if((i+1) % 4 === 0){
clone.style.marginRight = "0";
}
clone.style.display = "block";
clone.className = "product";
clone.children[0].innerHTML = json[i].id;
clone.children[1].children[0].src = json[i].img;
clone.children[2].innerHTML = json[i].txt;
clone.children[3].innerHTML = json[i].price;
parent.appendChild(clone);
}
// 动态添加购物车列表
var add_to_cart = $(".add_to_cart",$(".con")[0]);
for(var j = 0,cartLen = add_to_cart.length; j < cartLen; j++){
add_to_cart[j].onclick = function(){
var cart_list = $(".cart_list",$(".header")[0]);
for(var k =0, cart_list_len = cart_list.length; k < cart_list_len; k++){
if(this.parentNode.children[0].innerHTML === $("li",$(".cart_list")[k])[0].innerHTML ){
var num = ++cart_list[k].children[3].innerHTML;
var prices2 = Number(cart_list[k].children[4].innerHTML.slice(1));
$("#total").text((Number($("#total").text()) + prices2).toFixed(2));
return;
}
}
var clone = $(".title",$(".header")[0])[0].cloneNode(true);
clone.className = "cart_list";
clone.children[0].innerHTML = this.parentNode.children[0].innerHTML;
clone.children[1].innerHTML = this.parentNode.children[1].innerHTML;
clone.children[2].innerHTML = this.parentNode.children[2].innerHTML;
clone.children[3].innerHTML = "1";
clone.children[4].innerHTML = this.parentNode.children[3].innerHTML;
clone.children[5].innerHTML = "<a href='javascript:void(0)' class='remove'>删除</a>";
$(".cart_list_box",$(".header")[0])[0].appendChild(clone);
var prices1 = Number(clone.children[4].innerHTML.slice(1));
$("#total").text((Number($("#total").text()) + prices1).toFixed(2));
// 删除购物车列表内指定商品
for(var l = 0,remove_len = $(".remove").length; l < remove_len; l++){
$(".remove")[l].onclick = function(){
if(confirm("确认删除该商品?")){
var price = (this.parentNode.parentNode.children[4].innerHTML).slice(1);
var num = this.parentNode.parentNode.children[3].innerHTML;
var removePrices = price * num;
$("#total").text( (Number($("#total").text()) - removePrices).toFixed(2));
this.parentNode.parentNode.parentNode.removeChild(this.parentNode.parentNode);
}
}
}
}
} // 清空购物车
$("#removeAll").click(function(){
for(var i = 0,len = $(".cart_list_box")[0].children.length; i < len; i++){
$(".cart_list_box")[0].removeChild($(".cart_list_box")[0].children[0]);
}
$("#total").text("00.00");
})
//去结算
$(".calc").click(function () {
window.location.href='http://www.baidu.com';
})
</script>
</body>
</html>
pc端 添加购物车示例的更多相关文章
- 淘宝购物车页面 PC端和移动端实战
最近花了半个月的时间,做了一个淘宝购物车页面的Demo.当然,为了能够更加深入的学习,不仅仅有PC端的固定宽度的布局,还实现了移动端在Media Query为768px以下(也就是实现了ipad,ip ...
- Ext-JS-Classic-Demo 面向pc端示例
基于Ext Js 6.5.1 面向pc端示例,低于此版本可能存在兼容问题,慎用 已忽略编译目录,请自行编译运行 Sencha Cmd 版本:v6.5.1.240 git地址:https://githu ...
- C#--图片上传(PC端和APP)保存及 跨域上传说明
手动跨域操作文件 补录:跨域访问文件夹文件是一种常见的需求,下面主要介绍的的通过代码使用具有权限账号的人来达到跨域操作文件的能力. 现在补充一下普通的一些需求场景,今天就遇到了一种需要经常需要登录远程 ...
- pygame开发PC端微信打飞机游戏
pygame开发PC端微信打飞机游戏 一.项目简介 1. 介绍 本项目类似曾经火爆的微信打飞机游戏.游戏将使用Python语言开发,主要用到pygame的API.游戏最终将会以python源文件gam ...
- PC端Web项目开发流程
从前一直再做前端,突然想到如果有一天领导让自己独立承担一个web 项目的话是否有足够的能力去接这个任务,要学会自己去搭建一些基础的工具信息.所有的这一切在心里都要有个大致的流程,不然真正做的时候难免会 ...
- 使用rem配置PC端自适应大屏
效果如下 使得大屏不论在什么宽高比例依然能展示全部数据 安装 npm install -S postcss-pxtorem rem配置思路 原先的rem函数是能解决大部分的问题的,如果展示不全,也可以 ...
- 第 31 章 项目实战-PC 端固定布局[3]
学习要点: 1.搜索区 2.插入大图 3.搜索框 主讲教师:李炎恢 本章主要开始使用学习用 HTML5 和 CSS3 来构建 Web 页面,第一个项目采用 PC 端固定布局来实现. 一.搜索区 本节课 ...
- 第 31 章 项目实战-PC端固定布局[2]
学习要点: 1.大纲算法 2.section和div 3.结构分析 主讲教师:李炎恢 本章主要开始使用学习用HTML5和CSS3来构建Web页面,第一个项目采用PC端 固定布局来实现. 一.大纲算法 ...
- 第 31 章 项目实战-PC端固定布局[1]
学习要点: 1.准备工作 2.创建项目 3.网站结构 4.CSS选择器 5.完成导航 主讲教师:李炎恢 本章主要开始使用学习用HTML5和CSS3来构建Web页面,第一个项目采用PC端 固定布局来实现 ...
随机推荐
- 学习类后回顾pickle及collections模块应用场景优化
1.首先创建一个类,并给出一个对象 class Dog(object): def __init__(self,name,kind,age): self.name=name self.kind=kind ...
- SIP协议简单介绍
sip协议是由IETF提出的IP电话信令协议,主要目的是为了解决ip网络中的信令控制,以及同软交换通信. sip协议类似http协议: 报文结构: start-line message-header ...
- Base64 空格,加号问题
缘由: 在一个项目中,app请求tcpdump日志与记录的日志内容不一致 请求%2B 识别成 + 请求 + 识别成 空格 这个在base64解密的时候会出现异常,base64需要的是加号,而不是空格 ...
- How to use “cat” command on “find” command's output?
You can do this with find alone using the -exec action: find /location -size 1033c -exec cat {} + {} ...
- (转)GANs and Divergence Minimization
GANs and Divergence Minimization 2018-12-22 09:38:27 This blog is copied from: https://colinraff ...
- Linux md5sum 的用法
MD5 算法常常被用来验证网络文件传输的完整性,防止文件被篡改.MD5 全称是报文摘要算法,此算法对任意长度 的信息逐位计算,产生一个二进制长度为 128 位(十六进制长度 32 位)的报文摘要,不同 ...
- VirtualBox运行出现“0x00000000指令引用的0x00000000内存。该内存不能为written” ,错误解决
win7 64位系统,运行virtual box 出现如下错误 错误原因:由于系统主题被破解导致的 解决办法: 1.管理员身份运行UniversalThemePatcher_1.5.22 x64,点击 ...
- [原]编译flightGear
参考:flightgear编译博客201705 flightGear是三维飞行仿真软件,这个款软件是开源的,我们尝试用其源码完整编译一遍这个工程,并使用它. 它用到里以下扩展库: 空气动力学库:JSB ...
- 文献导读 | A Pan-Cancer Analysis of Enhancer Expression in Nearly 9000 Patient Samples
Chen, H., Li, C., Peng, X., Zhou, Z., Weinstein, J.N., Liang, H. and Cancer Genome Atlas Research Ne ...
- 原生JS获取DOM 节点到浏览器顶部的距离或者左侧的距离
关于js获取dom 节点到浏览器顶/左部的距离,Jquery里面有封装好的offset().top/offset().left,只到父级的顶/左部距离position().top/position() ...