angularjs增改查

来源:互联网 发布:易观数据怎么样 编辑:程序博客网 时间:2024/06/07 19:08
<!DOCTYPE html><html ng-app="UsersApp"><head>    <meta charset="UTF-8">    <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">    <script type="text/javascript" src="jquery.1.12.4.js"></script>    <script type="text/javascript" src="angular-1.3.0.js"></script>    <title>用户</title>    <script type="text/javascript">        var app = angular.module("UsersApp", []);        app.controller("UsersCtrl", function ($scope) {            $scope.data = [                {                    id: 1,                    name: "aa",                    password: "aa",                    age: 10,                    sex: ""                },                {                    id: 2,                    name: "bb",                    password: "bb",                    age: 20,                    sex: ""                },                {                    id: 3,                    name: "cc",                    password: "cc",                    age: 30,                    sex: ""                },                {                    id: 4,                    name: "dd",                    password: "dd",                    age: 40,                    sex: ""                }            ];            var id = 1;            $scope.add = function () {                $scope.data.push({                    id: id++,                    name: $scope.name,                    password: $scope.password,                    age: $scope.age,                    sex: $scope.sex                });                $scope.name = "";                $scope.password = "";                $scope.age = "";                $scope.sex = "";                $scope.addUserIsShow = false;            };            $scope.addUser = function () {                $scope.addUserIsShow = true;            };            $scope.editUser = function (index) {                var user = $scope.data[index];                $scope.e_name = user.name;                $scope.e_old_password = "";                $scope.e_password = "";                $scope.e_repassword = "";                $scope.editUserIsShow = true;                $scope.index = index;            };            $scope.edit = function () {//                对比第一次密码和第二次密码的一致性                if ($scope.e_password != $scope.e_repassword) {                    alert("两次密码不一致!");                    return;                }                $scope.data[$scope.index].password = $scope.e_password;                $scope.addUserIsShow = false;            };            var old_data = $scope.data;            $scope.searchByName = function () {                $scope.data = [];                for (var i in old_data) {                    if (old_data[i].name == $scope.s_name) {                        $scope.data.push(old_data[i]);                    }                }            };        });        $(function () {            $("input[name='check_all']").click(function () {                var chked = this.checked;                $("input[name='users']").each(function () {                    this.checked = chked;                });            });        });    </script></head><body ng-controller="UsersCtrl"><div>    <input type="text" ng-model="s_name" placeholder="用户名查询" ng-change="searchByName()"/></div><!--//添加用户的列表--><table border="1">    <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="user in data">        <td>            <input type="checkbox" name="users"/>        </td>        <td>{{ user.id }}</td>        <td>{{ user.name }}</td>        <td>{{ user.password }}</td>        <td>{{ user.age }}</td>        <td>{{ user.sex }}</td>        <td>            <button ng-click="editUser($index)">修改密码</button>        </td>    </tr></table><!--//添加用户到列表--><button ng-click="addUser()">添加用户</button><div ng-show="addUserIsShow">    <table border="1">        <tr>            <td>                用户名:            </td>            <td>                <input type="text" ng-model="name"/>            </td>        </tr>        <tr>            <td>                密码:            </td>            <td>                <input type="text" ng-model="password"/>            </td>        </tr>        <tr>            <td>                年龄:            </td>            <td>                <input type="text" ng-model="age"/>            </td>        </tr>        <tr>            <td>                性别:            </td>            <td>                <input type="text" ng-model="sex"/>            </td>        </tr>        <tr>            <td colspan="2" align="center">                <button ng-click="add()">提交</button>            </td>        </tr>    </table></div><!--//更改密码和确认密码--><div ng-show="editUserIsShow">    <table border="1">        <tr>            <td>                用户名:            </td>            <td>                <input type="text" ng-model="e_name" disabled/>            </td>        </tr>        <tr>            <td>                旧密码:            </td>            <td>                <input type="text" ng-model="e_old_password"/>            </td>        </tr>        <tr>            <td>                新密码:            </td>            <td>                <input type="text" ng-model="e_password"/>            </td>        </tr>        <tr>            <td>                确认密码:            </td>            <td>                <input type="text" ng-model="e_repassword"/>            </td>        </tr>        <tr>            <!--//提交按钮-->            <td colspan="2" align="center">                <input type="hidden" ng-model="index"/>                <button ng-click="edit()">提交</button>            </td>        </tr>    </table></div></body></html>
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 撞车对方全责不赔钱怎么办 电梯坏了没人修怎么办 电工超作证丢了怎么办 设计师直接找电梯厂家怎么办 研究生补助申请期限过了怎么办 我的电脑图标没了怎么办 苹果锁频密码忘了怎么办 孕妇被降职降薪怎么办 公司降职降薪员工不同意怎么办 企业因为经营不善要降薪该怎么办 调岗不降薪我该怎么办? 怀孕后强制调岗怎么办 有限公司法人变更后债务怎么办 有限公司法人跑路债务怎么办 网上买票身份信息待核验怎么办 微信买票身份核验失败怎么办 买高铁票待核验怎么办 网上购票身份待核验怎么办 b站稿件版权原因怎么办 已离职老板打电话说账有问题怎么办 开到应急刹车道怎么办 自动挡的车刹车失灵怎么办 自动挡的车如果刹车失灵怎么办 手动挡汽车刹车失灵怎么办 车辆没有年检出了交通事故怎么办 跟着大货车闯了红灯怎么办 在万家金服买的电子产品坏了怎么办 汽车被油笔画了怎么办? 挂到别人车跑了怎么办 浪琴手表保修卡掉了怎么办 事故车辆维修和报废怎么办 4.2货车拉缸了怎么办 工作中与同事发生矛盾怎么办 和领导关系闹僵怎么办 内倒窗户卡住了怎么办 支付宝存在安全风险怎么办 地铁车站空调坏了怎么办 面试防汛值班发生灾情你怎么办 怀孕上班路途太远怎么办 硕士错过校招应该怎么办 收银员收多了钱怎么办