^^

<!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>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值