<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript" src="js/angular.js" ></script>
<script>
var app = angular.module("myApp",[]);
app.controller("myCtrl",function($scope){
$scope.paixu="-age";
$scope.student = [{name:"张三",age:45,pinyin:"zhangsan",work:"总经理"},
{name:"李四",age:43,pinyin:"lisi",work:"设计师"},
{name:"王五",age:40,pinyin:"wangwu",work:"工程师"},
{name:"赵六",age:33,pinyin:"zhaoliu",work:"工程师"},
{name:"周七",age:31,pinyin:"zhouqi",work:"人事经理"}];
$scope.tjflog=false;
$scope.tj = function(){
$scope.tjflog=true;
}
//添加
$scope.bc = function(){
if($scope.name==null||$scope.name==""){
alert("名字不能为空");
}else{
if((isNaN($scope.age))){
alert("年龄必须为数字");
}else{
if($scope.pinyin==null||$scope.pinyin==""){
alert("拼音必填");
}else{
if($scope.work==null||$scope.work==""){
alert("工作必须填");
}else{
$scope.student.push({name:$scope.name,age:parseInt($scope.age),pinyin:$scope.pinyin,work:$scope.work});
$scope.name="";
$scope.age="";
$scope.pinyin="";
$scope.work="";
$scope.tjflog=false;
}
}
}
}
}
//删除
$scope.sc=function(name){
for (a in $scope.student) {
if($scope.student[a].name==name){
$scope.student.splice(a,1);
}
}
}
$scope.cx=function(){
if($scope.newname==null||$scope.newname==""){
alert("内容不能为空");
}else{
if($scope.newname=="傻逼"){
$scope.newname="";
alert("这是一个敏感字符");
}else{
var flog=false;
for(a in $scope.student){
if($scope.student[a].name.indexOf($scope.newname)>=0){
var flog=true;
}
}
if(flog){
$scope.newnames=$scope.newname;
}else{
alert("未查询到相关内容");
$scope.newnames="";
}
}
}
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript" src="js/angular.js" ></script>
<script>
var app = angular.module("myApp",[]);
app.controller("myCtrl",function($scope){
$scope.paixu="-age";
$scope.student = [{name:"张三",age:45,pinyin:"zhangsan",work:"总经理"},
{name:"李四",age:43,pinyin:"lisi",work:"设计师"},
{name:"王五",age:40,pinyin:"wangwu",work:"工程师"},
{name:"赵六",age:33,pinyin:"zhaoliu",work:"工程师"},
{name:"周七",age:31,pinyin:"zhouqi",work:"人事经理"}];
$scope.tjflog=false;
$scope.tj = function(){
$scope.tjflog=true;
}
//添加
$scope.bc = function(){
if($scope.name==null||$scope.name==""){
alert("名字不能为空");
}else{
if((isNaN($scope.age))){
alert("年龄必须为数字");
}else{
if($scope.pinyin==null||$scope.pinyin==""){
alert("拼音必填");
}else{
if($scope.work==null||$scope.work==""){
alert("工作必须填");
}else{
$scope.student.push({name:$scope.name,age:parseInt($scope.age),pinyin:$scope.pinyin,work:$scope.work});
$scope.name="";
$scope.age="";
$scope.pinyin="";
$scope.work="";
$scope.tjflog=false;
}
}
}
}
}
//删除
$scope.sc=function(name){
for (a in $scope.student) {
if($scope.student[a].name==name){
$scope.student.splice(a,1);
}
}
}
$scope.cx=function(){
if($scope.newname==null||$scope.newname==""){
alert("内容不能为空");
}else{
if($scope.newname=="傻逼"){
$scope.newname="";
alert("这是一个敏感字符");
}else{
var flog=false;
for(a in $scope.student){
if($scope.student[a].name.indexOf($scope.newname)>=0){
var flog=true;
}
}
if(flog){
$scope.newnames=$scope.newname;
}else{
alert("未查询到相关内容");
$scope.newnames="";
}
}
}
}
});
</script>
</head>
<body ng-app="myApp" ng-controller="myCtrl">
<center>
姓名查询条件<input type="text" ng-model="newname"/>
<select ng-model="paixu">
<option value="-age">按年龄正序</option>
<option value="age">按年龄倒序</option>
</select>
<table border="1px soilde #000" width="400px">
<tr>
<th>姓名</th>
<th>年龄</th>
<th>拼音</th>
<th>职位</th>
<th>操作</th>
</tr>
<tr ng-repeat="student in student |filter:{'name':newnames} |orderBy:(paixu)">
<td>{{student.name}}</td>
<td>{{student.age}}</td>
<td>{{student.pinyin}}</td>
<td>{{student.work}}</td>
<td><button ng-click="sc(student.name)" style="cursor: pointer;">删除</button></td>
</tr>
</table>
<button style="margin-left: 100px;" ng-click="cx()">查询</button>
<button ng-click="tj()">添加用户</button>
<table ng-show="tjflog">
<tr>
<td>姓名</td>
<td><input type="text" ng-model="name"/></td>
</tr>
<tr>
<td>年龄</td>
<td><input type="text" ng-model="age"/></td>
</tr>
<tr>
<td>拼音</td>
<td><input type="text" ng-model="pinyin"/></td>
</tr>
<tr>
<td>职位</td>
<td><input type="text" ng-model="work"/></td>
</tr>
<tr align="center">
<td colspan="2"><button ng-click="bc()">保存</button></td>
</tr>
</table>
});
</script>
</head>
<body ng-app="myApp" ng-controller="myCtrl">
<center>
姓名查询条件<input type="text" ng-model="newname"/>
<select ng-model="paixu">
<option value="-age">按年龄正序</option>
<option value="age">按年龄倒序</option>
</select>
<table border="1px soilde #000" width="400px">
<tr>
<th>姓名</th>
<th>年龄</th>
<th>拼音</th>
<th>职位</th>
<th>操作</th>
</tr>
<tr ng-repeat="student in student |filter:{'name':newnames} |orderBy:(paixu)">
<td>{{student.name}}</td>
<td>{{student.age}}</td>
<td>{{student.pinyin}}</td>
<td>{{student.work}}</td>
<td><button ng-click="sc(student.name)" style="cursor: pointer;">删除</button></td>
</tr>
</table>
<button style="margin-left: 100px;" ng-click="cx()">查询</button>
<button ng-click="tj()">添加用户</button>
<table ng-show="tjflog">
<tr>
<td>姓名</td>
<td><input type="text" ng-model="name"/></td>
</tr>
<tr>
<td>年龄</td>
<td><input type="text" ng-model="age"/></td>
</tr>
<tr>
<td>拼音</td>
<td><input type="text" ng-model="pinyin"/></td>
</tr>
<tr>
<td>职位</td>
<td><input type="text" ng-model="work"/></td>
</tr>
<tr align="center">
<td colspan="2"><button ng-click="bc()">保存</button></td>
</tr>
</table>
</center>
</body>
</html>
</body>
</html>