选中按钮删除

    <!DOCTYPE html>
<html>

    <head>
        <meta charset="UTF-8">
        <script type="text/javascript" src="js/angular.js">
        style
        </script>
        <script type="text/javascript">
            var app = angular.module("myApp", []);
            app.controller("myCtrl", function($scope, $http) {
                $http({
                    mothod: "get",
                    url: "zuoye.json"

                }).then(function chenggong(response) {

                    console.log(response.data);
                    $scope.dian = response.data

                }, function shibai() {
                    alert("失败")

                });

                $scope.update = function(n) {

                    if(window.confirm("确认要修改价格?")) {

                        var p = window.prompt("请输入修改的价格", n.price);
                        if(isNaN(p)) {
                            alert("输入有误")
                        } else {

                            n.price = p;
                        }
                    }

                }

                $scope.pi = function() {

                    var arr = [];
                    for(n in $scope.dian) {
                        if($scope.dian[n].state) {
                            arr.push($scope.dian[n].name);

                        }
                    }
                    if(arr.length <= 0) {
                        alert("请选择")

                    } else {

                        if(window.confirm("确认要删除?")) {
                            for(a in arr) {

                                    for(index in $scope.dian)
                                    {
    
                                        if(arr[a] == $scope.dian[index].name)
                                                {
                                            $scope.dian.splice(index, 1)
                                                    }
                                    }

                            }

                        }
                    }
                }

                //shanchu

                $scope.del = function(name, state) {
                    if(state) {
                        if(window.confirm("确定要删除" + name + "么")) {
                            //alert(state);

                            for(index in $scope.dian) {
                                if(name == $scope.dian[index].name) {

                                    $scope.dian.splice(index, 1);
                                }

                            }
                        }

                    } else {
                        alert("请选择");
                    }

                }
                $scope.flag = "";
                $scope.lie = "num"

                $scope.paixu = function(nubmer) {

                    $scope.lie = nubmer;
                    if($scope.flag = "") {
                        $scope.flag = "-"

                    } else {

                        scope.flag = ""
                    }

                }

                //全选
                $scope.selectAll = false;
                $scope.selectAllFun = function() {
                    if($scope.selectAll) {
                        for(index in $scope.dian) {
                            $scope.dian[index].state = true;
                        }
                    } else {

                        for(index in $scope.dian) {
                            $scope.dian[index].state = false;
                        }
                    }

                }
                //反选
                
$scope.dan=function(){
    
    var flag=false;
    for(index in $scope.dian){
        if(!$scope.dian[index].state){
            flag=true;
            
        }
        
        if(flag)
        {
            $scope.selectAll=false
            
        }else{
            
            $scope.selectAll=true;
        }
    }
}
            });

            //反选
        </script>
        <title></title>
    </head>

    <body ng-app="myApp" ng-controller="myCtrl">
        <center>
            <input type="text" placeholder="产品名称" ng-model="cha" /> 排序
            <select ng-model="sel">
                <option value="">排序方式</option>
                <option value="num">id正序</option>
                <option value="-num">id到序</option>
                <option value="price">价格正序</option>
                <option value="-price">价格倒xu</option>

            </select>
            <button ng-click="pi()">批量删除</button>
            <fieldset id="">
                <legend>添加商品列表</legend>
                <table border="1" cellspacing="0" cellpadding="10" style="margin-top: 30px;">
                <tr>
                    <th>
                        <input type="checkbox" ng-model="selectAll" ng-click="selectAllFun()" /></th>
                    <th ng-click=" paixu( 'num') ">产品编号</th>
                    <th ng-click="paixu( 'name') ">产品名称</th>
                    <th ng-price="paixu( 'price') ">产品价格</th>
                    <th>操作</th>

                </tr>
                <tr ng-repeat=" n in dian | filter:{ 'name': cha} | orderBy:sel ">
                    <td><input type="checkbox" ng-model="n.state" ng-click="dan()" /></td>
                    <td>{{n.num}}</td>
                    <td>{{n.name}}</td>
                    <td>{{n.price | currency :"(RMA) "}}</td>
                    <td><button ng-click="del(n.name,n.state) ">删除</button><button ng-click="update(n) ">修改</button></td>
                </tr>
            </table>
                
            </fieldset>
            
        </center>

    </body>

</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值