<!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>
angular 添加用户
最新推荐文章于 2021-01-15 15:35:44 发布