购物车 2

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title></title>
		<style>
			#da{
				width: 600px;
				height: 1000px;
			}
			table{
				width: 600px;
			}
			
			select{
				background: #999999;
			}
			#xiao{
				width: 400px;
				height: 25px;
				margin-top: 20px;
				float: left;
			}
			#yi{
				width: 150px;
				height: 25px;
				background: #00FF66;
				float: left;
			}
			#er{
				width: 150px;
				height: 25px;
				background: #00FF66;
				float: right;
			}
			#san{
				width: 150px;
				height: 25px;
				float: right;
				margin-top: 20px;
			}
			
			.css1{
				background-color:#00FF99;
			}
			.css2{
				background: #FF3399;
			}
		</style>
		
		<script src="js/jquery-1.11.1.js"></script>
		<script src="js/jquery-1.11.1.min.js"></script>
		<script type="text/javascript" src="js/angular.min.js" ></script>
		<script type="text/javascript" src="js/lib/js/angular/angular.js" ></script>
		<script>
			var app = angular.module("linrenjiang",[]);
			app.controller("conl",function($scope){
				
				$scope.selname = "";
				$scope.px = '-num*s.price';
				$scope.sj = true;
				$scope.stus = [{
					id : 001,
					name: "手机",
					num : 3,
					price : 1000
				},{
					id : 002,
					name: "电脑",
					num : 3,
					price : 2000
				},{
					id : 003,
					name: "电视",
					num : 6,
					price : 500
				}];
				
				$scope.add = function(){
					$scope.stus.push({  
                    id : 004,
					name: "冰箱",
					num : 2,
					price : 15000
                    });  
				}
				$scope.del = function(na){
					if(window.confirm("你确定删除" + na + "吗")) {  
                        for(index in $scope.stus) {  
                            if(na == $scope.stus[index].name) {  
                                $scope.stus.splice(index, 1);  
                            }  
                        }  
                    }  
				}
				
				 //总价格  
                $scope.prices = function() {  
                    var p = 0;  
                    for(var x = 0; x < $scope.stus.length; x++) {  
                        p += $scope.stus[x].num * $scope.stus[x].price;  
                    }  
                    return p;  
                }  
                //总数量  
                $scope.nums = function() {  
                    var p = 0;  
                    for(var x = 0; x < $scope.stus.length; x++) {  
                        p += $scope.stus[x].num;  
                    }  
                    return p;  
                }  
                
                //清空购物车
  				 $scope.delAll=function(){  
                	$scope.stus.splice(0);
                } 

			});
		</script>
	</head>
	<body ng-app="linrenjiang" ng-controller="conl">
		<center>
			<div id="da">
				<h2 style="background: #D7FF86; width: 200px;">我的购物车详情</h2>
				<button ng-click="add()" style="float: left; width: 80px; background: red;">添加</button>
				<input type="text" ng-model="selname"  style="float: right; width: 250px; height: 25px; background: url(img/s.PNG)"/>
			<br />
			<table cellpadding="0" cellspacing="0" border="1px">
				<thead>
					<tr style="background: #999999;">
						<th ng-click="px = 'id';sj=!sj">商品编号</th>
						<th>商品名称</th>
						<th>商品数量</th>
						<th>商品单价</th>
						<th ng-click="px = 'num*s.price'; sj=!sj">价格小计</th>
						<th>操作</th>
					</tr>
				</thead>
				<tbody>
					<tr ng-repeat="s in stus | filter:{name:selname} | orderBy:px:sj" class="{{$even ? 'css1' : 'css2' }}" align="center">
						<td>{{s.id}}</td>
						<td>
							<span ng-click="f=true">{{s.name}}</span>
							<span ng-show="f">
								<input ng-model="s.name" /><button ng-click="f=fales">保存</button>
							</span>
						</td>
						<td><input type="number" ng-model="s.num" min="1"/></td>
						<td>{{s.price}}</td>
						<td>{{s.num*s.price}}</td>
						<td>
							<button ng-click="del(s.name)" style="background: yellow;">移除</button>
						</td>
					</tr>
				</tbody>
			</table>
			<br />
			<div style="width: 600px; height: 30px;">
				<div id="xiao">
				<div id="yi">
					商品总数:{{nums()}}
				</div>
				
				<div id="er">
					商品总价:{{prices()}}
				</div>
				
				
				
			</div>
			
				<div id="san">
					<button ng-click="delAll()" style="background: yellow;">清空购物车</button>
				</div>
			</div>

		</div>
		
		</center>
		
		
		
	</body>
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Vue 2购物车的完整实现包括以下几个关键步骤: 1. 创建Vue实例:使用Vue框架创建一个新的Vue实例,作为整个应用的根组件。 2. 数据管理:在Vue实例中定义数据属性,用于存储购物车中的商品列表、商品数量、总价等信息。 3. 商品列表展示:在页面上展示商品列表,可以使用v-for指令遍历商品数组,并显示每个商品的名称、价格等信息。 4. 添加商品到购物车:为每个商品添加一个“添加到购物车”按钮,并绑定点击事件。在事件处理函数中,将选中的商品添加到购物车数据中,并更新总价。 5. 修改商品数量:为每个商品在购物车中绑定一个输入框,用于修改商品数量。对输入框绑定一个change事件,在事件处理函数中更新对应商品的数量,并计算新的总价。 6. 删除商品:为每个商品在购物车中添加一个“删除”按钮,并绑定点击事件。在事件处理函数中,从购物车数据中移除对应的商品,并更新总价。 7. 结算功能:添加一个“结算”按钮,并绑定点击事件。在事件处理函数中,可以进行一些结算逻辑,例如生成订单、清空购物车等操作。 8. 样式美化:使用CSS样式对购物车页面进行美化,使其更加符合用户体验和界面设计需求。 需要注意的是,上述实现仅是一个基本的购物车功能,你可以根据具体需求进行扩展和优化,例如加入购物车数量限制、价格计算规则、登录验证等功能。同时,也可以通过与后端API进行数据交互,实现购物车数据的持久化和同步。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值