<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script src="js/angular.min.js" type="text/javascript" charset="utf-8"></script>
<script src="js/jquery-3.2.1.min.js" type="text/javascript" charset="utf-8"></script>
</head>
<body ng-app="myapp" ng-controller="myctrl">
<input type="text" placeholder="输入商品名" ng-model="name"/>
<select ng-model="price">
<option value="">按单价排序</option>
<option value="gprice">单价倒序</option>
<option value="-gprice">单价正序</option>
</select>
<table border="1" width="60%">
<tr style="background-color: gray;">
<th>id</th>
<th>商品名</th>
<th>商品数量</th>
<th>商品单价</th>
<th>商品总价</th>
<th>删除</th>
</tr>
<tr ng-repeat="x in shops | filter:{gname:name} | orderBy:price" id="t">
<td>{{x.gid}}</td>
<td>{{x.gname}}</td>
<td>
<input type="number" value="{{x.gnum}}" ng-model="x.gnum" ng-change="adc(x.gnum)"/>
</td>
<td>{{x.gprice|currency:"$"}}</td>
<td>{{(x.gprice*x.gnum)|currency:"$"}}</td>
<td>
<input type="button" name="" id="" value="删除" ng-click="del($index)"/>
</td>
</tr>
</table>
<button ng-click="kk()">清空购物车</button>
<script type="text/javascript">
var app = angular.module("myapp",[]);
app.controller("myctrl",function($scope){
$scope.shops =
[{ "gid": 001, "gname": "手机", "gnum": 3, "gprice": 1000, "gcount": 3000 },
{ "gid": 002, "gname": "电脑", "gnum": 3, "gprice": 2000, "gcount": 6000 },
{ "gid": 003, "gname": "电视", "gnum": 6, "gprice": 500, "gcount": 3000 }]
$scope.del = function(index){
$scope.shops.splice(index,1);
}
$scope.kk=function(){
$scope.shops="";
}
$scope.adc = function(a){
for (var i = 0; i < $scope.shops.length; i++) {
if($scope.shops[i].gnum == a){
if($scope.shops[i].gnum == 0){
if(confirm("确定删除吗")){
$scope.shops.splice(i,1);
}
}
}
}
}
})
</script>
</body>
</html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script src="js/angular.min.js" type="text/javascript" charset="utf-8"></script>
<script src="js/jquery-3.2.1.min.js" type="text/javascript" charset="utf-8"></script>
</head>
<body ng-app="myapp" ng-controller="myctrl">
<input type="text" placeholder="输入商品名" ng-model="name"/>
<select ng-model="price">
<option value="">按单价排序</option>
<option value="gprice">单价倒序</option>
<option value="-gprice">单价正序</option>
</select>
<table border="1" width="60%">
<tr style="background-color: gray;">
<th>id</th>
<th>商品名</th>
<th>商品数量</th>
<th>商品单价</th>
<th>商品总价</th>
<th>删除</th>
</tr>
<tr ng-repeat="x in shops | filter:{gname:name} | orderBy:price" id="t">
<td>{{x.gid}}</td>
<td>{{x.gname}}</td>
<td>
<input type="number" value="{{x.gnum}}" ng-model="x.gnum" ng-change="adc(x.gnum)"/>
</td>
<td>{{x.gprice|currency:"$"}}</td>
<td>{{(x.gprice*x.gnum)|currency:"$"}}</td>
<td>
<input type="button" name="" id="" value="删除" ng-click="del($index)"/>
</td>
</tr>
</table>
<button ng-click="kk()">清空购物车</button>
<script type="text/javascript">
var app = angular.module("myapp",[]);
app.controller("myctrl",function($scope){
$scope.shops =
[{ "gid": 001, "gname": "手机", "gnum": 3, "gprice": 1000, "gcount": 3000 },
{ "gid": 002, "gname": "电脑", "gnum": 3, "gprice": 2000, "gcount": 6000 },
{ "gid": 003, "gname": "电视", "gnum": 6, "gprice": 500, "gcount": 3000 }]
$scope.del = function(index){
$scope.shops.splice(index,1);
}
$scope.kk=function(){
$scope.shops="";
}
$scope.adc = function(a){
for (var i = 0; i < $scope.shops.length; i++) {
if($scope.shops[i].gnum == a){
if($scope.shops[i].gnum == 0){
if(confirm("确定删除吗")){
$scope.shops.splice(i,1);
}
}
}
}
}
})
</script>
</body>
</html>