<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script src="js/angular.min.js"></script>
<script src="js/jquery-1.11.1.js"></script>
<script>
var app = angular.module("linrenjiang",[]);
app.controller("conl",function($scope){
$scope.stus = [{
name:"VIVO X20",
cound:3,
price:3200
},{
name:"OPPO R9",
cound:2,
price:2200
},{
name:"华为荣耀",
cound:1,
price:4200
}];
$scope.talshow = true;
$scope.del = function(name){
if(window.confirm("确定删除"+name+"吗?")){
for(index in $scope.stus){
if(name == $scope.stus[index].name){
$scope.stus.splice(index,1);
}
}
}
if($scope.stus == "" || $scope.stus == null){
alert("空了");
$scope.talshow = false;
}
};
$scope.sum = function(){
var num = 0;
for (var i in $scope.stus){
num = num + $scope.stus[i].cound*$scope.stus[i].price;
}
return num;
}
})
</script>
</head>
<body ng-app="linrenjiang" ng-controller="conl">
<div id="dahezi">
<table border="2px" ng-show="talshow">
<tr>
<th>商品名称</th>
<th>商品数量</th>
<th>商品单价</th>
<th>小计</th>
<th>操作</th>
</tr>
<tr ng-repeat="s in stus">
<td>{{s.name}}</td>
<td>{{s.cound}}</td>
<td>{{s.price | currency:"RMB¥:"}}</td>
<td>{{s.cound*s.price | currency:"RMB¥:"}}</td>
<td><input ng-click="del(s.name)" type="button" value="删除"/></td>
</tr>
<tr>
<td>总金额:{{sum()|currency:"RMB¥:"}}</td>
</tr>
</table>
</div>
</body>
</html>
过滤 与删除
最新推荐文章于 2022-08-03 10:29:59 发布