购物车1




<!DOCTYPE html>

<html>
<head>
<meta charset="UTF-8">
<title></title>
<script src="../js/ionic.bundle.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../js/jquery-1.11.1.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
var app = angular.module("myapp",[]).controller("myctrl",function ($scope,$http) {
$http.get("http://result.eolinker.com/rR1VBtT56a6bb220c10b3d44b65b4787a8aec03c4ec32ce?uri=ThirdTest").then(function (success) {
$scope.goods = success.data;
//alert($scope.goods .length);
});
//初始化隐藏
$scope.toad=false;
//单个删除
$scope.del=function (index) {
$scope.goods.splice(index,1);
}
//计算总价
$scope.getTotal=function () {
//初始化总价
var total = 0;
for (var i = 0; i < $scope.goods.length; i++) {
total = total+($scope.goods[i].price*$scope.goods[i].number);
}
return total;
}
//点击减号,,
$scope.jian=function (index) {
if ($scope.goods[index].number < 2) {//删除整个商品
var flag = confirm("是否删除这个商品");
if (flag) {//
$scope.del();
}
}else{
$scope.goods[index].number--;
}
}
//清空购物车
$scope.delAll=function () {
$scope.goods=[];
$scope.toad= true;
}
})
</script>
</head>
<body ng-app="myapp" ng-controller="myctrl" style="width: 700px;">
<h2>我的购物车</h2>
<button ng-click="delAll()" style="float: right;" ng-show="!toad">清空购物车</button>
<span ng-show="toad">您的购物车为空,<a href="#">去商城逛逛</a></span>
<table border="1px" cellspacing="0" cellpadding="0" width="700px" ng-show="!toad">
<tr>
<td><input type="checkbox" ng-model="ischeck" ng-change="changeCheck()" /></td>
<td>name</td>
<td ng-click="px='-price'">price</td>
<td>number</td>
<td ng-click="px='+(number*price)'">totalPrice</td>
<td>option</td>
</tr>
<tr ng-repeat="s in goods|orderBy:px">
<td><input type="checkbox" ng-model="ischeck" /></td>
<td>{{s.name}}</td>
<td>{{s.price|currency:"¥"}}</td>
<td><button ng-click="s.number=s.number+1">+</button><input type="text" ng-model="s.number"/><button ng-click="jian($index)">-</button></td>
<td>{{s.price*s.number|currency:"¥"}}</td>
<td><button ng-click="del($index)">删除</button></td>
</tr>
</table>
<span ng-show="!toad">商品总价:{{getTotal()|currency:"¥"}}</span>
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值