<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<style type="text/css">
tbody tr:nth-child(even)
{
background: #00000;
}
tbody tr:nth-child(odd)
{
background: greenyellow;
}
<html>
<head>
<meta charset="utf-8" />
<title></title>
<style type="text/css">
tbody tr:nth-child(even)
{
background: #00000;
}
tbody tr:nth-child(odd)
{
background: greenyellow;
}
</style>
<script type="text/javascript" src="js/angular.js" ></script>
<script>
var app = angular.module("myApp",[]);
app.controller("myCtrl",function($scope){
$scope.student = [{
"name":"张三",
"age":45,
"py":"zhangsan",
"zw":"总经理",
},{
"name":"李四",
"age":43,
"py":"lisi",
"zw":"设计师",
},{
"name":"王五",
"age":40,
"py":"wangwu",
"zw":"工程师",
},{
"name":"赵六",
"age":33,
"py":"zhaoliu",
"zw":"工程师",
},{
"name":"周七",
"age":32,
"py":"zhouqi",
"zw":"人事经理",
}];
$scope.px = "";
//删除
$scope.sc = function(name){
if (window.confirm("确定删除?")) {
for (index in $scope.student) {
if (name == $scope.student[index].name) {
$scope.student.splice(index,1);
}
}
}
}
//添加
$scope.bc = function(){
if ($scope.newname == null || $scope.newname == "") {
alert("姓名不能为空");
}else if(isNaN($scope.newname)){
alert("姓名不能是数字");
}else{
if ($scope.newage == null || $scope.newage == "") {
alert("姓名不能为空");
}else if (isNaN($scope.newage)) {
alert("年龄格式错误,必须数字");
}else if($scope.newage.length != 2){
alert("年龄必须是2位");
}else{
if ($scope.newpy == null || $scope.newpy == "") {
alert("拼音不能为空");
}else{
if ($scope.newzw == null || $scope.newzw == "") {
alert("拼音不能为空");
}else{
var newShop = {
name:$scope.newname,
age:parseInt($scope.newage),
py:$scope.newpy,
zw:$scope.newzw,
num:1,
state:false
};
}
}
}
}
$scope.student.push(newShop);
}
//查询
$scope.searchname = function(){
var flag = false;
$scope.searchshow = "";
for (index in $scope.student) {
if ($scope.search == $scope.student[index].name) {
flag = true;
}
}
if ($scope.search == null || $scope.search == "") {
alert("输入框不能为空");$scope.searchshow="";
}else if (flag) {
alert("姓名存在");
$scope.searchshow = $scope.search;
}else{
alert("姓名不存在");
$scope.searchshow=null;
}
}
});
</script>
</head>
<body ng-app="myApp" ng-controller="myCtrl">
<center>
姓名查询条件:<input ng-model="search" />
<button ng-click="searchname()">查询</button>
<select ng-model="px">
<option value="">按年龄排序</option>
<option value="age">按年龄正序</option>
<option value="-age">按年龄倒序</option>
</select><br /><br />
<table border="1px" cellpadding="10" cellspacing="0">
<tr>
<th>姓名</th>
<th>年龄</th>
<th>拼音</th>
<th>职位</th>
<th>操作</th>
</tr>
<tr ng-repeat="p in student | orderBy:px | filter:searchshow" align="center">
<td>{{p.name}}</td>
<td>{{p.age}}</td>
<td>{{p.py}}</td>
<td>{{p.zw}}</td>
<!--变小手-->
<td><button ng-click="sc(p.name)" style="cursor: pointer;">删除</button></td>
</tr>
</table>
<button>添加用户</button>
<form>
姓名:<input type="text" ng-model="newname"/><br /><br />
年龄:<input type="text" ng-model="newage"/><br /><br />
拼音:<input type="text" ng-model="newpy"/><br /><br />
职位:<input type="text" ng-model="newzw"/><br /><br />
<button ng-click="bc()">保存</button>
</form>
</center>
</body>
</html>
<script>
var app = angular.module("myApp",[]);
app.controller("myCtrl",function($scope){
$scope.student = [{
"name":"张三",
"age":45,
"py":"zhangsan",
"zw":"总经理",
},{
"name":"李四",
"age":43,
"py":"lisi",
"zw":"设计师",
},{
"name":"王五",
"age":40,
"py":"wangwu",
"zw":"工程师",
},{
"name":"赵六",
"age":33,
"py":"zhaoliu",
"zw":"工程师",
},{
"name":"周七",
"age":32,
"py":"zhouqi",
"zw":"人事经理",
}];
$scope.px = "";
//删除
$scope.sc = function(name){
if (window.confirm("确定删除?")) {
for (index in $scope.student) {
if (name == $scope.student[index].name) {
$scope.student.splice(index,1);
}
}
}
}
//添加
$scope.bc = function(){
if ($scope.newname == null || $scope.newname == "") {
alert("姓名不能为空");
}else if(isNaN($scope.newname)){
alert("姓名不能是数字");
}else{
if ($scope.newage == null || $scope.newage == "") {
alert("姓名不能为空");
}else if (isNaN($scope.newage)) {
alert("年龄格式错误,必须数字");
}else if($scope.newage.length != 2){
alert("年龄必须是2位");
}else{
if ($scope.newpy == null || $scope.newpy == "") {
alert("拼音不能为空");
}else{
if ($scope.newzw == null || $scope.newzw == "") {
alert("拼音不能为空");
}else{
var newShop = {
name:$scope.newname,
age:parseInt($scope.newage),
py:$scope.newpy,
zw:$scope.newzw,
num:1,
state:false
};
}
}
}
}
$scope.student.push(newShop);
}
//查询
$scope.searchname = function(){
var flag = false;
$scope.searchshow = "";
for (index in $scope.student) {
if ($scope.search == $scope.student[index].name) {
flag = true;
}
}
if ($scope.search == null || $scope.search == "") {
alert("输入框不能为空");$scope.searchshow="";
}else if (flag) {
alert("姓名存在");
$scope.searchshow = $scope.search;
}else{
alert("姓名不存在");
$scope.searchshow=null;
}
}
});
</script>
</head>
<body ng-app="myApp" ng-controller="myCtrl">
<center>
姓名查询条件:<input ng-model="search" />
<button ng-click="searchname()">查询</button>
<select ng-model="px">
<option value="">按年龄排序</option>
<option value="age">按年龄正序</option>
<option value="-age">按年龄倒序</option>
</select><br /><br />
<table border="1px" cellpadding="10" cellspacing="0">
<tr>
<th>姓名</th>
<th>年龄</th>
<th>拼音</th>
<th>职位</th>
<th>操作</th>
</tr>
<tr ng-repeat="p in student | orderBy:px | filter:searchshow" align="center">
<td>{{p.name}}</td>
<td>{{p.age}}</td>
<td>{{p.py}}</td>
<td>{{p.zw}}</td>
<!--变小手-->
<td><button ng-click="sc(p.name)" style="cursor: pointer;">删除</button></td>
</tr>
</table>
<button>添加用户</button>
<form>
姓名:<input type="text" ng-model="newname"/><br /><br />
年龄:<input type="text" ng-model="newage"/><br /><br />
拼音:<input type="text" ng-model="newpy"/><br /><br />
职位:<input type="text" ng-model="newzw"/><br /><br />
<button ng-click="bc()">保存</button>
</form>
</center>
</body>
</html>