angular 添加用户

<!DOCTYPE html>
<html ng-app="myapp">
<head lang="en">
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="text/javascript" src="jquery.1.12.4.js"></script>
    <script type="text/javascript" src="angular-1.3.0.js"></script>
    <!--<script src="jquery.1.12.4.js"></script>-->
    <script>
        var app=angular.module("myapp",[]);

        app.controller("UserCtrl", function ($scope) {
            $scope.data=[
                {
                    id:1,
                    name:"张三",
                    pw:"123",
                    age:18,
                    sex:"男"
                },
                {
                    id:2,
                    name:"王五",
                    pw:"123",
                    age:12,
                    sex:"男"
                },
                {
                    id:3,
                    name:"李四",
                    pw:"123",
                    age:11,
                    sex:"男"
                }
            ];

            var i=3;
            $scope.add=function () {
                i=i+1;
                var useraa={
                    id:i,
                    name:$scope.username,
                    pw:$scope.password,
                    age:$scope.age,
                    sex:$scope.sex
                };
                $scope.data.push(useraa);
                $scope.username="";
                $scope.password="";
                $scope.age="";
                $scope.sex="";
                $scope.adduserngshow=false;
            };

            $scope.adduser = function () {
                $scope.adduserngshow=true;
            };

            $scope.edituser= function (index) {
                var user=$scope.data[index];
                $scope.indexx=index;
                $scope.e_username=user.name;
                $scope.e_old_password = "";
                $scope.e_password = "";
                $scope.e_repassword = "";
                $scope.eidtuserngshow=true;
            };

            $scope.eidt= function () {
                if($scope.e_password!=$scope.e_repassword){
                    alert("两次密码不一致");
                    return;
                }
                $scope.data[$scope.indexx].pw=$scope.e_password;
                $scope.eidtuserngshow=false;
            };

            //用户名查询



        });

        //全选全不选
        $(function () {
            $("input[name='check_all']").click(function () {
                var chked=this.checked;
                $("input[name='users']").each(function(){
                    this.checked=chked;
                })
            });
        });
    </script>
</head>
<body ng-controller="UserCtrl">
    <div>
        <input type="text" placeholder="用户名查询" ng-model="selectname">
    </div>

    <table border="1px" cellspacing="0px" cellpadding="0px" align="center">
        <tr>
            <th><input type="checkbox" name="check_all"></th>
            <th>id</th>
            <th>用户名</th>
            <th>密码</th>
            <th>年龄</th>
            <th>性别</th>
            <th>操作</th>
        </tr>
        <tr ng-repeat="d in data | filter :{'name':selectname} | filter : {'age':selectname} | filter : {'sex' : selectname}">
            <td><input type="checkbox" name="users"></td>
            <td>{{d.id}}</td>
            <td>{{d.name}}</td>
            <td>{{d.pw}}</td>
            <td>{{d.age}}</td>
            <td>{{d.sex}}</td>
            <td><button ng-click="edituser($index)">修改密码</button></td>
        </tr>
    </table>

    <button style="text-align: center; background-color: #007aff; display: block; margin: 10px auto" ng-click="adduser()">添加用户</button>

    <div ng-show="adduserngshow">
        <table align="center" border="1px" cellspacing="0px" cellpadding="0px" >
            <tr>
                <th>用户名:</th>
                <td><input type="text" ng-model="username" placeholder="请输入用户名"></td>
            </tr>

            <tr>
                <th>密码:</th>
                <td><input type="text" ng-model="password" placeholder="请输入密码"></td>
            </tr>

            <tr>
                <th>年龄:</th>
                <td><input type="text" ng-model="age" placeholder="请输入年龄"></td>
            </tr>

            <tr>
                <th>性别:</th>
                <td><input type="text" ng-model="sex" placeholder="请输入性别"></td>
            </tr>

            <tr>
                <td colspan="2" align="center">
                    <button ng-click="add()">提交</button>
                </td>
            </tr>

        </table>

    </div>



    <div ng-show="eidtuserngshow">
        <table align="center" border="1px" cellspacing="0px" cellpadding="0px" >
            <tr>
                <th>用户名:</th>
                <td><input type="text" ng-model="e_username" disabled></td>
            </tr>

            <tr>
                <th>旧密码:</th>
                <td><input type="text" ng-model="e_old_password"></td>
            </tr>

            <tr>
                <th>新密码:</th>
                <td><input type="text" ng-model="e_password"></td>
            </tr>

            <tr>
                <th>重复密码:</th>
                <td><input type="text" ng-model="e_repassword"></td>
            </tr>

            <tr>
                <td colspan="2" align="center">
                    <input type="hidden" ng-model="indexx">
                    <button ng-click="eidt()">提交</button>
                </td>
            </tr>

        </table>

    </div>


</body>
</html>  

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值