购物车加减计算总价
2017-12-20 15:35
218 查看
<!DOCTYPE html>
<html>
b25d
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript" src="../../js/angular/angular.js"></script>
<script>
var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope) {
$scope.shops = [{
name: "苹果",
price: 3,
num: 5,
state: false
}, {
name: "梨子",
price: 4,
num: 2,
state: false
}, {
name: "香蕉",
price: 3,
num: 3,
state: false
}];
//数量减一
$scope.lessNum = function(shop) {
if(shop.num >= 1) {
shop.num--;
$scope.zongjai = 0;
for(index in $scope.shops) {
if($scope.shops[index].state) {
$scope.zongjai = ($scope.shops[index].price * $scope.shops[index].num) + $scope.zongjai;
}
}
}
}
//数量加一
$scope.addNum = function(shop) {
shop.num++;
$scope.zongjai = 0;
for(index in $scope.shops) {
if($scope.shops[index].state) {
$scope.zongjai = ($scope.shops[index].price * $scope.shops[index].num) + $scope.zongjai;
}
}
}
//计算总价
$scope.zongjai = 0;
$scope.sum = function() {
for(index in $scope.shops) {
if($scope.shops[index].state) {
$scope.zongjai = ($scope.shops[index].price * $scope.shops[index].num) + $scope.zongjai;
}
}
}
})
</script>
</head>
<body ng-app="myApp" ng-controller="myCtrl">
<center>
<h3>购物车</h3>
<table border="1px solid blue" cellpadding="10" cellspacing="0">
<thead>
<tr>
<th><input type="checkbox" /></th>
<th>商品名</th>
<th>商品价格</th>
<th>商品数量</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="shop in shops">
<td>
<input type="checkbox" ng-click="sum()" ng-model="shop.state" />
</td>
<td>{{shop.name}}</td>
<td>{{shop.price}}</td>
<td>
<button ng-click="lessNum(shop)">-</button>
<input type="text" size="1" value="{{shop.num}}" />
<button ng-click="addNum(shop)">+</button>
</td>
<td width="50px"><button>删除</button></td>
</tr>
<tr>
<td colspan="5">
总价:<span ng-bind="zongjai"></span>元
</td>
</tr>
</tbody>
</table>
</center>
</body>
</html>
<html>
b25d
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript" src="../../js/angular/angular.js"></script>
<script>
var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope) {
$scope.shops = [{
name: "苹果",
price: 3,
num: 5,
state: false
}, {
name: "梨子",
price: 4,
num: 2,
state: false
}, {
name: "香蕉",
price: 3,
num: 3,
state: false
}];
//数量减一
$scope.lessNum = function(shop) {
if(shop.num >= 1) {
shop.num--;
$scope.zongjai = 0;
for(index in $scope.shops) {
if($scope.shops[index].state) {
$scope.zongjai = ($scope.shops[index].price * $scope.shops[index].num) + $scope.zongjai;
}
}
}
}
//数量加一
$scope.addNum = function(shop) {
shop.num++;
$scope.zongjai = 0;
for(index in $scope.shops) {
if($scope.shops[index].state) {
$scope.zongjai = ($scope.shops[index].price * $scope.shops[index].num) + $scope.zongjai;
}
}
}
//计算总价
$scope.zongjai = 0;
$scope.sum = function() {
for(index in $scope.shops) {
if($scope.shops[index].state) {
$scope.zongjai = ($scope.shops[index].price * $scope.shops[index].num) + $scope.zongjai;
}
}
}
})
</script>
</head>
<body ng-app="myApp" ng-controller="myCtrl">
<center>
<h3>购物车</h3>
<table border="1px solid blue" cellpadding="10" cellspacing="0">
<thead>
<tr>
<th><input type="checkbox" /></th>
<th>商品名</th>
<th>商品价格</th>
<th>商品数量</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="shop in shops">
<td>
<input type="checkbox" ng-click="sum()" ng-model="shop.state" />
</td>
<td>{{shop.name}}</td>
<td>{{shop.price}}</td>
<td>
<button ng-click="lessNum(shop)">-</button>
<input type="text" size="1" value="{{shop.num}}" />
<button ng-click="addNum(shop)">+</button>
</td>
<td width="50px"><button>删除</button></td>
</tr>
<tr>
<td colspan="5">
总价:<span ng-bind="zongjai"></span>元
</td>
</tr>
</tbody>
</table>
</center>
</body>
</html>
相关文章推荐
- HTML angular购物车:加减按钮改变数量+全选+低于1时提示删除商品+计算所有商品总价+清空购物车+单独删除+输入内容小于1时,自动变为1+反选
- jQuery实现购物车多物品数量的加减+总价计算
- Angular.js用法(二):购物车数量加减及总价计算
- JQuery购物车多物品数量的加减+总价计算
- HTML angular购物车:加减按钮改变数量+全选+低于1时提示删除商品+计算所有商品总价+清空购物车+单独删除+输入内容小于1时,自动变为1+反选
- jQuery实现购物车多物品数量的加减+总价计算
- jQuery实现购物车多物品数量的加减+总价+删除计算
- 实现购物车多物品数量的加减+总价计算
- 硅谷商城5--购物车商品选中和商品总价计算
- 原生JS实现购物车的添加删除,以及总价计算的功能
- 韩经哲月考4_购物车计算总价
- Android_二级列表购物车之增删改查,全选反选,加减器,价钱数量计算
- vue实现商品加减计算总价的实例代码
- jquery实现购物车数量加减,价格计算功能
- Js写购物车全选全不选计算单价总价代码
- 动态计算购物车总价(数量可选),nextSibling属性
- JQuery实现购物车数量加减总价累加
- jQuery实现购物车物品数量的加减并自动计算价格
- 购物车中计算checkBox选中总价功能的实现
- HTML 购物车计算总价+添加或者减少商品数量