<script>
var app=angular.module("myApp",[]);
app.controller("myCtrl",function($scope){
$scope.products=[{
id:1,
name:"nanjing",
pass:147258,
age:21,
sex:"女"
},{
id:2,
name:"xiaoxin",
pass:148155,
age:18,
sex:"女"
},{
id:3,
name:"hah",
pass:25555,
age:20,
sex:"男"
}];
//姓名查找
$scope.search="";
//批量删除
$scope.delete=function(){
if(confirm("您确定删除吗")){
for (var i=0;i<$scope.products.length;i++) {
if($scope.products[i].state==true){
$scope.products.splice(i,1);
i--;
}
}
}
}
//添加
$scope.tj=function(){
var newname=$scope.add_name;
var newpass=$scope.add_pass;
var newage=$scope.add_age;
var newsex=$scope.add_sex;
$scope.arr=[];
if(newname=="" || newname==undefined){
$scope.arr.push("用户名不能为空");
$scope.nn=("用户名不能为空");
}
if(newpass=="" || newpass==undefined){
$scope.arr.push("密码不能为空");
$scope.qq=("密码不能为空");
}
if(newage=="" || newage==undefined){
$scope.arr.push("年龄不能为空");
$scope.ww=("年龄不能为空");
}
if(newsex=="" || newsex==undefined){
$scope.arr.push("性别必填");
$scope.ee=("性别必填");
}
if($scope.arr.length==0){
var pro={
id:$scope.add_id,
name:newname,
pass:$scope.add_pass,
age:$scope.add_age,
sex:$scope.add_sex
}
$scope.products.push(pro);
$scope.add_id="";
$scope.isshow=false;
}
}
//年龄区间查询
$scope.nlsize=function(age){
if($scope.nl=="" || $scope.nl==undefined){
return true;
}else{
var arr=$scope.nl.split("-");
var max=arr[1];
var min=arr[0];
if(age>min && age<max){
return true;
}else{
return false;
}
}
}
//删除全部
$scope.deleteAll=function(){
$scope.products.splice(0);
}
//删除
$scope.delProduct=function(clumn){
var arr=[];
if(confirm("您去定删除吗")){
for (index in $scope.products) {
if($scope.products[index].id==clumn){
$scope.products.splice(index,1);
}
}
}
}
});
</script>
</head>
<body ng-app="myApp" ng-controller="myCtrl">
<center>
<div class="aa">
<h1>Air Show</h1>
<input placeholder="gao" ng-model="search"/>
<select ng-model="xbcx">
<option value="">性别查询</option>
<option>男</option>
<option>女</option>
</select>
<select ng-model="nl">
<option value="">年龄查找</option>
<option>1-10</option>
<option>10-20</option>
<option>20-30</option>
</select>
<button ng-click="deleteAll()">删除全部</button>
<button ng-click="delete()">批量删除</button><br /><br />
<table border="1" cellpadding="10" cellspacing="0">
<thead>
<tr>
<th><input type="checkbox"></th>
<th>序号</th>
<th>姓名</th>
<th>密码</th>
<th>年龄</th>
<th>性别</th>
<th>操作</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="pro in products | filter:{name:search} | filter:{sex:xbcx}" ng-if="nlsize(pro.age)">
<td><input type="checkbox" ng-model="pro.state"></td>
<td>{{pro.id}}</td>
<td>{{pro.name}}</td>
<td>{{pro.pass}}</td>
<td><span ng-hide="xg">{{pro.age}}</span><span ng-show="xg"><input type="text" ng-model="pro.age"><button ng-click="xg=false">保存</button></span></td>
<td>{{pro.sex}}</td>
<td><button ng-click="xg=true">修改</button></td>
<td><button ng-click="delProduct(pro.id)">删除</button></td>
</tr>
</tbody>
</table>
<button ng-click="isshow=true">添加用户</button>
<div ng-show="isshow">
id<input type="text" ng-model="add_id"/><br />
用户名<input type="text" ng-model="add_name"/><span ng-show="nn.length!=0" style="background-color: yellow" >{{nn}}</span><br />
密码<input type="text" ng-model="add_pass"/><span ng-show="qq.length!=0" style="background-color: yellow">{{qq}}</span><br />
年龄<input type="text" ng-model="add_age"/><span ng-show="ww.length!=0" style="background-color: yellow">{{ww}}</span><br />
性别<input type="text" ng-model="add_sex"/><span ng-show="ee.length!=0" style="background-color: yellow">{{ee}}</span><br />
<button ng-click="tj()">提交</button>
</div>
</div>
</center>
</body>
var app=angular.module("myApp",[]);
app.controller("myCtrl",function($scope){
$scope.products=[{
id:1,
name:"nanjing",
pass:147258,
age:21,
sex:"女"
},{
id:2,
name:"xiaoxin",
pass:148155,
age:18,
sex:"女"
},{
id:3,
name:"hah",
pass:25555,
age:20,
sex:"男"
}];
//姓名查找
$scope.search="";
//批量删除
$scope.delete=function(){
if(confirm("您确定删除吗")){
for (var i=0;i<$scope.products.length;i++) {
if($scope.products[i].state==true){
$scope.products.splice(i,1);
i--;
}
}
}
}
//添加
$scope.tj=function(){
var newname=$scope.add_name;
var newpass=$scope.add_pass;
var newage=$scope.add_age;
var newsex=$scope.add_sex;
$scope.arr=[];
if(newname=="" || newname==undefined){
$scope.arr.push("用户名不能为空");
$scope.nn=("用户名不能为空");
}
if(newpass=="" || newpass==undefined){
$scope.arr.push("密码不能为空");
$scope.qq=("密码不能为空");
}
if(newage=="" || newage==undefined){
$scope.arr.push("年龄不能为空");
$scope.ww=("年龄不能为空");
}
if(newsex=="" || newsex==undefined){
$scope.arr.push("性别必填");
$scope.ee=("性别必填");
}
if($scope.arr.length==0){
var pro={
id:$scope.add_id,
name:newname,
pass:$scope.add_pass,
age:$scope.add_age,
sex:$scope.add_sex
}
$scope.products.push(pro);
$scope.add_id="";
$scope.isshow=false;
}
}
//年龄区间查询
$scope.nlsize=function(age){
if($scope.nl=="" || $scope.nl==undefined){
return true;
}else{
var arr=$scope.nl.split("-");
var max=arr[1];
var min=arr[0];
if(age>min && age<max){
return true;
}else{
return false;
}
}
}
//删除全部
$scope.deleteAll=function(){
$scope.products.splice(0);
}
//删除
$scope.delProduct=function(clumn){
var arr=[];
if(confirm("您去定删除吗")){
for (index in $scope.products) {
if($scope.products[index].id==clumn){
$scope.products.splice(index,1);
}
}
}
}
});
</script>
</head>
<body ng-app="myApp" ng-controller="myCtrl">
<center>
<div class="aa">
<h1>Air Show</h1>
<input placeholder="gao" ng-model="search"/>
<select ng-model="xbcx">
<option value="">性别查询</option>
<option>男</option>
<option>女</option>
</select>
<select ng-model="nl">
<option value="">年龄查找</option>
<option>1-10</option>
<option>10-20</option>
<option>20-30</option>
</select>
<button ng-click="deleteAll()">删除全部</button>
<button ng-click="delete()">批量删除</button><br /><br />
<table border="1" cellpadding="10" cellspacing="0">
<thead>
<tr>
<th><input type="checkbox"></th>
<th>序号</th>
<th>姓名</th>
<th>密码</th>
<th>年龄</th>
<th>性别</th>
<th>操作</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="pro in products | filter:{name:search} | filter:{sex:xbcx}" ng-if="nlsize(pro.age)">
<td><input type="checkbox" ng-model="pro.state"></td>
<td>{{pro.id}}</td>
<td>{{pro.name}}</td>
<td>{{pro.pass}}</td>
<td><span ng-hide="xg">{{pro.age}}</span><span ng-show="xg"><input type="text" ng-model="pro.age"><button ng-click="xg=false">保存</button></span></td>
<td>{{pro.sex}}</td>
<td><button ng-click="xg=true">修改</button></td>
<td><button ng-click="delProduct(pro.id)">删除</button></td>
</tr>
</tbody>
</table>
<button ng-click="isshow=true">添加用户</button>
<div ng-show="isshow">
id<input type="text" ng-model="add_id"/><br />
用户名<input type="text" ng-model="add_name"/><span ng-show="nn.length!=0" style="background-color: yellow" >{{nn}}</span><br />
密码<input type="text" ng-model="add_pass"/><span ng-show="qq.length!=0" style="background-color: yellow">{{qq}}</span><br />
年龄<input type="text" ng-model="add_age"/><span ng-show="ww.length!=0" style="background-color: yellow">{{ww}}</span><br />
性别<input type="text" ng-model="add_sex"/><span ng-show="ee.length!=0" style="background-color: yellow">{{ee}}</span><br />
<button ng-click="tj()">提交</button>
</div>
</div>
</center>
</body>