<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <script src="../test29/angular.min.js"></script> <script> var myapp=angular.module("myapp",[]); myapp.controller("myCtrl",function ($scope) { $scope.data=[{ name:'a',pass:'111',age:20,sex:'男' },{ name:'b',pass:'2341',age:40,sex:'女' },{ name:'c',pass:'2341',age:22,sex:'女' },{ name:'d',pass:'2541',age:10,sex:'男' },{ name:'e',pass:'2322',age:40,sex:'女' }] //全部删除的功能 $scope.deleteall=function () { var a=confirm("确定要全部删除吗") if(a){ $scope.data.splice(0,$scope.data.length); } } //添加用户 $scope.rece=false; $scope.shows=function () { $scope.rece=!$scope.rece; } $scope.submits=function () { $scope.data.push({name:$scope.newname,pass:$scope.newpass,age:$scope.newage,sex:$scope.newsex}); $scope.newname=''; $scope.newpass=''; $scope.newage=''; $scope.newsex=''; $scope.rece=false; } $scope.recel=false; $scope.inde; $scope.show1=function (index) { $scope.recel=!$scope.recel; $scope.inde=index; } //修改密码 $scope.submits1=function () { if($scope.oldpass==$scope.data[$scope.inde].pass){ if ($scope.newpass1==$scope.newpass2){ $scope.data[$scope.inde].pass=$scope.newpass1; }else { alert('两次密码不一致'); } }else { alert('密码错误'); } $scope.newname1=''; $scope.oldpass=''; $scope.newpass1=''; $scope.newpass2=''; $scope.recel=false; } }) </script> </head> <body ng-app="myapp" ng-controller="myCtrl"> <input type="text" placeholder="用户名查询" ng-model="sort"> <input type="text" placeholder="年龄范围查询" ng-model="sort1"> <select> <option>男</option> <option>女</option> </select> <button ng-click="deleteall()">全部删除</button> <table> <thead> <th>id</th> <th>用户名</th> <th>密码</th> <th>性别</th> <th>操作</th> </thead> <tbody> <tr ng-repeat="item in data|filter:sort|filter:sort1"> <td>{{$index}}</td> <td>{{item.name}}</td> <td>{{item.pass}}</td> <td>{{item.age}}</td> <td>{{item.sex}}</td> <td><button ng-click="shows1($index)">修改密码</button></td> </tr> </tbody> </table> <button ng-click="shows()">添加用户</button> <div ng-show="rece"> 用户名:<input type="text" ng-model="newname"><br> 密码:<input type="text" ng-model="newpass"><br> 年龄:<input type="text" ng-model="newage"><br> 性别:<input type="text" ng-model="newsex"><br> <button ng-click="submits()">提交</button> </div> <div ng-show="recel"> 用户名:<input type="text" ng-model="newname1"><br> 旧密码:<input type="text" ng-model="oldpass"><br> 新密码:<input type="text" ng-model="newpass1"><br> 确认密码:<input type="text" ng-model="newpass2"><br> <button ng-click="submits1()">提交</button> </div> </body> </html>
模糊查询全部删除添加用户
最新推荐文章于 2023-01-24 19:56:07 发布