<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>购物车</title>
<script type="text/javascript" src="js/jquery-1.11.1.min.js"></script>
<style>
*{margin: 0;padding: 0}
a{text-decoration: none;}
ul li{float: left;list-style: none;}
#wrapper{max-width: 640px;min-width: 320px;font-size: 12px;font-family: "微软雅黑";height: 370px;margin: 50px auto;}
#wrapper #content{width: 100%;float: left;}
#wrapper #content .goods_lists{width: 100%;float:left; }
#wrapper #content .goods_lists .list{width:96%;padding: 0 2%;}
#wrapper #content .goods_lists .list li{width: 100%;height: 100px;border: 1px solid #c7000a;margin-top: 15px;float: left;background: #fffefe;}
.goods_lists .list li .checkbox{width: 12px;height: 12px;position: relative;border:1px solid #999 ;float: left;margin-top: 45px;margin-left: 2%;z-index: 1}
.goods_lists .list li .checkbox .c_xz{position: absolute;top: -1px;left: 0px;width: 12px;height: 12px;display: none;}
.goods_lists .list li .door{float: left;width: 74px;height: 74px;margin: 12px 0 0 3%;border: 1px solid #999;}
.goods_lists .list li .l_right{width: 62%;height: 74px;float: left;margin-top: 12px;padding-left: 2%}
.goods_lists .list li .l_right .l_r_desc{max-width: 100%;overflow: hidden;color: #555; line-height:22px;height: 22px;}
.goods_lists .list li .l_right .price{color: #555;}
.goods_lists .list li .l_right .price span{color: #c7000a;}
.goods_lists .list li .l_right .old_price{text-decoration: line-through;float: left;width: 100%;color: #555}
.goods_lists .list li .l_right .l_bot{width: 66%;height:20px;float: right; color: #555;}
.goods_lists .list li .l_right .l_bot p{float: left;padding-top: 2px;}
.goods_lists .list li .l_right .l_bot input{float: left;width:17%;height: 14px;text-align: center;border:1px solid #999;margin-top: 3px; }
.goods_lists .list li .l_right .l_bot a{float: left; margin: 3px 3%;}
.goods_lists .list li .l_right .l_bot .rubbish{margin-left: 5%;}
#wrapper #content .checkout{float: left;width: 100%;height: 50px;background: #fffefe;border-top:1px solid #999;border-bottom: 1px solid #999;margin-top: 20px; }
#wrapper #content .checkout .c_left{float: left;width: 47%;height: 35px;font-size: 12px;color: #555;padding-left: 3%;line-height: 50px;}
#wrapper #content .checkout .c_left span{color: #c7000a;}
#wrapper #content .checkout .c_right{float: left;width: 50%;height: 50px;background: #c7000a;color: #fefdfd;text-align: center;font-size: 14px;line-height: 50px;}
</style>
</head>
<body>
<div id="wrapper">
<div id="content">
<div class="goods_lists">
<ul id="listbox" class="list">
<li>
<div class='checkbox'>
<div class='c_xz'><img src='images/checkbox.png' width='12' height='12'></div>
</div>
<a class='door' href='javascript:void(0);'><img src='images/list1.jpg' width='74' height='74' alt='阿迪达斯男鞋' /></a>
<div class='l_right'>
<p class='l_r_desc'>ADIDAS阿迪达斯 三叶草经典板鞋 ZX700跑步鞋</p>
<p class='price'>价格:<span>¥<span class='money' data-money='461'>461.00</span></span></p>
<p class='old_price'>885.00</p>
<div class='l_bot'>
<p>数量 :</p>
<a class='remove' href='javascript:void(0);'><img src='images/remove.png' width='15' height='15'></a>
<input type='text' data-max='10' class='num' value='1' />
<a class='add' href='javascript:void(0);'><img src='images/add.png' width='15' height='15'></a>
<a class='rubbish' href='javascript:void(0);'><img src='images/rubbish.png' width='14' height='16'></a>
</div>
</div>
</li>
<li>
<div class='checkbox'>
<div class='c_xz'><img src='images/checkbox.png' width='12' height='12'></div>
</div>
<a class='door' href='javascript:void(0);'><img src='images/list2.jpg' width='74' height='74' alt='iphone6s plus' /></a>
<div class='l_right'>
<p class='l_r_desc'>Apple/苹果 iPhone 6s Plus Android6.0操作系统</p>
<p class='price'>价格:<span>¥<span class='money' data-money='3999.99'>3999.99</span></span></p>
<p class='old_price'>5768.00</p>
<div class='l_bot'>
<p>数量 :</p>
<a class='remove' href='javascript:void(0);'><img src='images/remove.png' width='15' height='15'></a>
<input type='text' data-max='10' class='num' value='1' />
<a class='add' href='javascript:void(0);'><img src='images/add.png' width='15' height='15'></a>
<a class='rubbish' href='javascript:void(0);'><img src='images/rubbish.png' width='14' height='16'></a>
</div>
</div>
</li>
</ul>
</div>
<div class="checkout">
<div class="c_left">
合计(不含运费): <span>¥<span id="sum">0.00</span></span>
</div>
<a href="javascript:">
<div class="c_right">
单子(<span id="count">0</span>)
</div>
</a>
</div>
</div>
</div> <script type="text/javascript">
$(function(){
//删除商品
$("#listbox").on("click",".rubbish",function(){
$(this).parents("li").remove();
tm_total();
}); //商品复选框的选中和不选中
$("#listbox").on("click",".checkbox",function(){
$(this).find(".c_xz").toggle();
tm_total();
}); //商品数量的添加和减少
$("#listbox").on("click",".add",function(){
var $input = $(this).prev();
var value = $input.val();
var max = $input.data("max");
value++;
if(value > max)value = max;
$input.val(value);
tm_total();
}).on("click",".remove",function(){
var $input = $(this).next();
var value = $input.val();
value--;
if(value<=0)value=1;
$input.val(value);
tm_total();
});
}); //求总和
function tm_total(){
var total = 0;
$("#listbox").find("li").each(function(){
var flag = $(this).find(".c_xz").is(":visible");
if(flag){
var money = $(this).find(".money").data("money");
var number = $(this).find(".num").val();
total += money * number;
}
});
//求用户购买了多少个商品
var length =$("#listbox").find(".c_xz:visible").length;
$("#count").text(length);
$("#sum").text(total);
}; </script> </body>
</html>

【JavaScript&jQuery】购物车自动结算的更多相关文章

  1. JavaScript jQuery 中定义数组与操作及jquery数组操作

    首先给大家介绍javascript jquery中定义数组与操作的相关知识,具体内容如下所示: 1.认识数组 数组就是某类数据的集合,数据类型可以是整型.字符串.甚至是对象Javascript不支持多 ...

  2. jQuery AutoComplete 自动补全

    jQuery.AutoComplete是一个基于jQuery的自动补全插件.借助于jQuery优秀的跨浏览器特性,可以兼容Chrome/IE/Firefox/Opera/Safari等多种浏览器. 特 ...

  3. jquery背景自动切换特效

    查看效果网址:http://keleyi.com/a/bjad/4kwkql05.htm 本特效的jquery版本只支持1.9.0以下. 代码如下: <!DOCTYPE html PUBLIC ...

  4. 30+最佳Ajax jQuery的自动完成插件的例子

    在这篇文章中,我们将介绍35个jQuery AJAX的自动完成提示例子. jQuery 的自动完成功能,使用户快速找到并选择一定的价值.每个人都想要快速和即时搜索输入栏位,因为这个原因,许 流行的搜索 ...

  5. GBin1插件推荐之马可波罗(Marco Polo),jQuery的自动补齐插件 - Autocomplete Plugin

    让我们Google一下"jQuery autocomplete plugin"(jquery自动补齐插件).在过去的4年中,我已经Google了很多次这个组合了.然而结果并没有变化 ...

  6. Javascript Jquery 中的数组定义与操作_子木玲_新浪博客

    body{ font-family: "Microsoft YaHei UI","Microsoft YaHei",SimSun,"Segoe UI& ...

  7. 在eclipse-jee-juno中配置Aptana对jQuery代码自动提示

    主要问题 在Aptana的Web Project中打开js文件有JavaScript的自动提示,但是在JavaEE项目中却没有. 版本 eclipse-jee-juno,即Eclipse 4.2的Ja ...

  8. jquery 图片自动无缝滚动

    <!DOCTYPE html><html><head> <meta charset="utf-8"> <meta http-e ...

  9. jQuery图片自动添加水印插件

    JS脚本(jQuery)为图片加水印效果预览:http://hovertree.com/texiao/jquery/94/ 本功能使用HTML5实现,可为图片加上文字水印,可设置文字,设置颜色,位置等 ...

随机推荐

  1. 成都Uber优步司机奖励政策(4月11日)

    滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...

  2. 4040 EZ系列之奖金 (拓扑)

    4040 EZ系列之奖金 时间限制: 1 s 空间限制: 64000 KB 题目等级 : 钻石 Diamond         题目描述 Description 由于无敌的WRN在2015年世界英俊帅 ...

  3. GlusterFS学习之路(一)GlusterFS初识

    一.GlusterFS简介 GlusterFS是Scale-Out存储解决方案Gluster的核心,它是一个开源的分布式文件系统,具有强大的横向扩展能力,通过扩展能够支持数PB存储容量和处理数千客户端 ...

  4. Python:静态方法、类方法、实例方法

    1. 静态方法@staticmethod (1)无需自身对象的self参数和自身类的cls参数,可直接通过 类名.方法名 进行调用 (2)Python中并不是真正意义上的静态方法,因为类定义本身就是个 ...

  5. Elasticsearch5.x版本中对Text类型进行聚合时提示illegal_argument_exception

    Having this field in my mapping "answer": { "type": "text", "fiel ...

  6. Laya 自适应 不拉伸处理

    Laya.init(640, Laya.Browser.width / 640 * 1028, WebGL); Laya.stage.scaleMode = "fixedwidth" ...

  7. OpenLDAP备份和恢复

    OpenLDAP中数据备份一般分为二种: 1)通过slapcat 指令进行备份 2)通过phpLDAPadmin控制台进行备份 备份方式1: 1)slapcat -v -l openldap-back ...

  8. 【Python入门总结】

    用了两周时间将python的基本语法和模块过了一遍,alex的视频也简单看了下;并且在项目中直接上了python解析语义的实现,初步感觉到了python语言的魅力.下一步,会按照廖雪峰的python学 ...

  9. PayPal接洽苹果 欲承接手机支付外包

    不久前,<华尔街日报>等媒体报道,苹果正计划利用iTunes内部支付功能,推出第三方手机支付服务.美国科技 新闻网站Recode1月30日引述消息人士称,移动支付领军厂商PayPal,目前 ...

  10. 如何开发一个 PyCharm 插件

    PyCharm 是很多 Python 开发者优先选择的 IDE,功能强大,跨平台,提供免费社区版,非常良心.如果你想自己给PyCharm添加一些功能怎么办呢?有两个办法: 通过提需求实现,到 JetB ...