angularjs

<script type="text/javascript">

    var app = angular.module("myApp",[]);
    app.controller("myController",function($scope,$http){
        $http.post("${pageContext.request.contextPath}/goods/selectAll")
        .success(function(obj){
            $scope.goods=obj;
        })
        
        $scope.reduce=function(index){
            var gid = $scope.goods[index].gid;
            $http.post("${pageContext.request.contextPath}/goods/reduce?gid="+gid)
            .success(function(){
                --$scope.goods[index].count;
                if($scope.goods[index].count<1){
                    if(confirm("确定删除吗?")){
                    
                    $scope.goods.splice(index,1);
                    alert("删除成功!");
                    $http.post("${pageContext.request.contextPath}/goods/delete?gid="+gid)
                    }
                    
                }
            })
        }
        
        $scope.add=function(index){
            var gid = $scope.goods[index].gid;
            $http.post("${pageContext.request.contextPath}/goods/jia?gid="+gid)
            .success(function(){
                ++$scope.goods[index].count;
            })
        }
    })
</script>



  </head>
 
  <body ng-app="myApp">
    <div ng-controller="myController" class = "container">
    欢迎&nbsp;&nbsp;<span style="color: red">${user.name}</span>&nbsp;&nbsp;登录
            <h2 style="color: red" align="center">购物车页面</h2>
        <table class = "table table-striped table-bordered table-hover">
            <thead>
                <tr class = "success">
                    <td>选择</td>
                    <td>商品id</td>
                    <td>商品名称</td>
                    <td>商品价格</td>
                    <td>商品数量</td>
                    
                </tr>
            </thead>
            
            <tbody>
                <tr ng-repeat="g in goods">
                    <td>
                        <input type="checkbox" value="{{g.gid}}">
                    </td>
                    <td>{{g.gid}}</td>
                    <td>{{g.gname}}</td>
                    <td>{{g.price}}</td>
                    <td>
                    <input class="btn btn-primary" type="button" value="-" ng-click="reduce($index)">
                    <input type="text" value="{{g.count}}" style="width: 30px;">
                    
                    <input class="btn btn-primary" type="button" value="+" ng-click="add($index)">
                    </td>
                </tr>
            </tbody>
        </table>
        <input class="btn btn-danger" type="button" value="添加到购物车" id="mai">
    </div>
  </body>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值