<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script src="js/angular.min.js"></script>
<script src="js/jquery-1.11.1.min.js"></script>
<script>
angular.module("myapp", [])
.controller("democ", function($scope, $filter) {
$scope.datas = [{
"id": 0,
"name": "张三",
"age": 45,
"pinyin": "zhangsan",
"zhiwei": "总经理",
},
{
"id": 1,
"name": "李四",
"age": 43,
"pinyin": "lisi",
"zhiwei": "设计师",
},
{
"id": 2,
"name": "王五",
"age": 40,
"pinyin": "wangwu",
"zhiwei": "工程师",
},
{
"id": 3,
"name": "赵六",
"age": 33,
"pinyin": "zhaoliu",
"zhiwei": "工程师",
},
{
"id": 4,
"name": "周七",
"age": 32,
"pinyin": "zhouqi",
"zhiwei": "人事经理",
},
]
$scope.goods = $scope.datas;
$scope.save = function() {
var i = $scope.datas.length+1;
$scope.tips = false;
$scope.avalArr = [];
if($scope.name == undefined || $scope.name == "") {
$scope.avalArr.push("用户名不能为空");
}
if($scope.pinyin == undefined || $scope.pinyin == "") {
$scope.avalArr.push("拼音不能为空");
}
if($scope.zhiwei == undefined || $scope.zhiwei == "") {
$scope.avalArr.push("职位不能为空");
}
if(!/^\d+$/.test($scope.age)) {
$scope.avalArr.push("年龄必须为有效数字");
return;
}
if($scope.avalArr > length > 0) {
$scope.tips = true;
} else {
var da = {
"name": $scope.name,
"age": $scope.age,
"pinyin": $scope.pinyin,
"zhiwei": $scope.zhiwei
};
$scope.datas.push(da);
$scope.isshow = false;
}
}
$scope.del = function(d) {
for(var i = 0; i < $scope.datas.length; i++) {
if($scope.datas[i].id == d.id) {
if(confirm("确定删除这一行吗?")) {
$scope.datas.splice(i, 1);
}
}
}
}
$scope.cha = function() {
if($scope.selname == null||$scope.selname =="") {
alert("输入不能为空");
return;
}
if($scope.selname.indexOf("我") != -1) {
alert("包含敏感词");
return;
}
var filter = $filter("filter");
var ch = filter($scope.goods, {
"name": $scope.selname
});
if(ch.length == 0) {
alert("没有匹配项");
} else {
$scope.datas = ch;
}
}
})
.filter("demof", function() {
return function(input) {
var ss = input.replace(/张/g, "**");
return ss;
};
})
</script>
<style>
tr {
text-align: center;
}
tr:nth-child(2n) {
background-color: #CCCCCA;
}
tr:hover{
background-color: red;
}
a {
text-decoration: none;
color: #000000;
}
</style>
</head>
<body ng-app="myapp" ng-controller="democ">
<div style="width: 800px; margin: 0 auto;">
姓名查询条件<input ng-model="selname" />
<select ng-model="selcha" ng-change="orderby">
<option value="">请选择</option>
<option value="-age">按年龄倒叙</option>
<option value="age">按年龄正叙</option>
</select>
<table border="1xp" style="width: 800px;">
<tr style="background-color:#787876 ;">
<td>姓名</td>
<td>年龄</td>
<td>拼音</td>
<td>职位</td>
<td>操作</td>
</tr>
<tr ng-repeat="da in datas|orderBy:selcha">
<td>{{da.name|demof}}</td>
<td>{{da.age}}</td>
<td>{{da.pinyin}}</td>
<td>{{da.zhiwei}}</td>
<td><button ng-click="del(da)"><a href="#">删除</a></button></td>
</tr>
</table>
<input type="button" ng-click="cha()" value="查询" />
<input type="button" ng-click="isshow=true" value="添加" />
<div ng-show="isshow">
姓名<input ng-model="name" /><br /> 年龄
<input ng-model="age" /><br /> 拼音
<input ng-model="pinyin" /><br /> 职位
<input ng-model="zhiwei" /><br />
<div style="width: 200px; background-color: pink;">
<ul>
<!-- 点击保存时,把不合法的信息都放入数组 valArr -->
<li ng-repeat="c in avalArr ">{{c}}</li>
</ul>
</div>
<input type="button" ng-click="save()" value="保存" />
</div>
</div>
</body>
</html>
用户敏感词 删除 添加
最新推荐文章于 2021-11-12 17:50:33 发布