body里面:
<input type="checkbox" ng-model="st" ng-click="quan()">全选
<ul ng-repeat="item in data">
<input type="checkbox" ng-model="item.check" ng-click="fu()">
<li>{{item.id}}</li>
<li>{{item.name}}</li>
<li>{{item.price}}</li>
<li><button ng-click="jia($index)">+</button><span ng-bind="item.num"></span><button ng-click="jian($index)">-</button><button ng-click="shan($index)">删除</button></li>
</ul>
<p><span ng-bind="money()"></span></p>
js:<script>
var app=angular.module("app",[]);
var items = [{}];
app.controller("ctr",function ($scope) {
$scope.data=items;
$scope.shan=function (index) {
$scope.data.splice(index,1);
}
$scope.jian=function (index) {
if($scope.data[index].num>0){
$scope.data[index].num--;
}else{
alert("空了");
}
}
$scope.jia=function (index) {
$scope.data[index].num++; } $scope.money=function () { var my=0; for (var i=0;i<$scope.data.length;i++){ if($scope.data[i].check==true){ my+=$scope.data[i].num*$scope.data[i].price; } } return "总价:"+my; } $scope.st=false; $scope.quan=function () { if($scope.st==true){ for (var i=0;i<$scope.data.length;i++){ $scope.data[i].check=true } }else { for (var i=0;i<$scope.data[i].length;i++){ $scope.data[i].check=false } } } $scope.fu=function () { var fale=0; for (var i=0;i<$scope.data.length;i++){ if($scope.data[i].check==true){ fale++; } } if(fale==$scope.data.length){ $scope.st=true }else{ $scope.st=false } } })</script>