angularJs删除一整行(Dome)

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <script type="text/javascript" src = "angular.min.js"></script>
    <style type="text/css">
        table{
            border: 1px solid #000;
            border-collapse:collapse;
        }
        td{
            border: 1px solid #000;
            width: 100px;
            text-align: center;
        }
    </style>
</head>
<body ng-app="myApp" ng-controller="controller">
    <div ng-init="persons = [{name:'张三',stu:1001,age:10,sex:'男'},
                             {name:'李四',stu:1002,age:14,sex:'女'},
                             {name:'二狗',stu:1003,age:34,sex:'女'},
                             {name:'王五',stu:1004,age:20,sex:'未知'}]">
    <table>
        <tr>
            <td>姓名</td>
            <td>学号</td>
            <td>年龄</td>
            <td>性别</td>
            <td>操作</td>
        </tr>
        <tr ng-repeat="obj in persons">
            <td ng-bind="obj.name"></td>
            <td ng-bind="obj.stu"></td>
            <td ng-bind="obj.age"></td>
            <td ng-bind="obj.sex"></td>
            <td><button ng-click="delete($index)">删除</button></td>
        </tr>
    </table>
    <script type="text/javascript">
        var app = angular.module("myApp",[]);
        app.controller("controller",function($scope){
            $scope.delete = function(index) {
                $scope.persons.splice(index,1 );
            };
        });
    </script>
</body>
</html>

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <script src="angular.min.js"></script>
    <style>
        table,td,th{
            border: 1px solid black;
            border-collapse: collapse;
        }
        td{
            width: 100px;
            text-align: center;
        }
    </style>
</head>
<body ng-app="app" ng-controller="myVC">

    <table>
        <tr>
            <th>姓名</th>
            <th>学号</th>
            <th>年龄</th>
            <th>性别</th>
            <th>操作</th>
        </tr>
        <tr ng-repeat = "stu in stuArr">
            <td ng-bind="stu.name"></td>
            <td ng-bind="stu.num"></td>
            <td ng-bind="stu.age"></td>
            <td ng-bind="stu.sex"></td>

            <!-- 按钮的点击事件,将当前按钮对应的对象传递到触发事件中 -->
            <!-- <td><input type="button" value="删除" ng-click="delete(stu)"></td> -->

            <!-- $index是ng-repeat中的下标 -->
            <td><input type="button" value="删除" ng-click="delete($index)"></td>
        </tr>
    </table>

    <script>
        var app = angular.module("app",[]);
        app.controller("myVC",function($scope){
            //定义数组
            $scope.stuArr = [
                {
                    name:"张三",
                    age:20,
                    sex:'男',
                    num:"1001"
                },{
                    name:"李四",
                    age:20,
                    sex:'男',
                    num:"1002"
                },{
                    name:"王五",
                    age:20,
                    sex:'男',
                    num:"1003"
                },{
                    name:"赵六",
                    age:20,
                    sex:'男',
                    num:"1004"
                }
            ];

            // $scope.delete = function(s){
            //     var index = $scope.stuArr.indexOf(s);
            //     console.log(index);
            //     $scope.stuArr.splice(index,1);
            // }

            $scope.delete = function(index){
                $scope.stuArr.splice(index,1);
            }
        });
    </script>
</body>
</html>
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值