<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Title</title> | |
<script src="wenjian/angular-1.5.5/angular.js"></script> | |
<script src="wenjian/angular-route.js"></script> | |
<script> | |
var app =angular.module("myApp",["ngRoute"]); | |
app.config | |
app.controller("myCtrl",function ($scope) { | |
$scope.users=[{ | |
name:"张三", | |
wz:"控球后卫", | |
size:11, | |
ps:999 | |
},{ | |
name:"李四", | |
wz:"大前锋", | |
size:21, | |
ps:888 | |
},{ | |
name:"王五", | |
wz:"小前锋", | |
size:23, | |
ps:777 | |
},{ | |
name:"赵六", | |
wz:"中锋", | |
size:10, | |
ps:666 | |
},{ | |
name:"周七", | |
wz:"得分后卫", | |
size:1, | |
ps:555 | |
}]; | |
$scope.Size="--请选择--" | |
$scope.psSize =function (ps,Size) { | |
if(Size=="--请选择--"){ | |
return true; | |
}else{ | |
var arr = Size.split("-"); | |
var ageMin = arr[0]; | |
var ageMax = arr[1]; | |
if(ps>ageMin && ps<ageMax){ | |
return true; | |
}else{ | |
return false; | |
} | |
} | |
} | |
$scope.addUser =function () { | |
$scope.myVar = !$scope.myVar; | |
} | |
$scope.tijiao = function(name1,wz1,size1,ps1){ | |
if(name1==""||name1==null && wz1==""|| wz1==null && size1==""|| size1==null){ | |
alert("不能为空") | |
}else { | |
var panduan = false; | |
var panduan1 = false; | |
var panduan2 = false; | |
for (var i = 0; i < $scope.users.length; i++) { | |
if ($scope.users[i].name === name1) { | |
alert("姓名已存在") | |
panduan=false; | |
}else{ | |
panduan=true | |
} | |
if ($scope.users[i].wz === wz1) { | |
alert("位置已存在") | |
panduan1=false; | |
}else{ | |
panduan1=true | |
} | |
if ($scope.users[i].size === size1) { | |
alert("号码已存在") | |
panduan2=false; | |
}else{ | |
panduan2=true | |
} | |
} | |
if(panduan==true&&panduan1==true&&panduan2==true){ | |
if (ps1 > 0&& ps1 < 1000){ | |
$scope.users.push({ | |
name: name1, | |
wz: wz1, | |
size: size1, | |
ps: ps1 | |
}) | |
}else { | |
alert("票数在0-1000之间") | |
} | |
} | |
} | |
} | |
}) | |
</script> | |
<style type="text/css"> | |
div{ | |
display: inline-block; | |
} | |
</style> | |
</head> | |
<body ng-app="myApp" ng-controller="myCtrl" style=" width: 500px; height: 300px; margin: 0 auto;"> | |
<div> | |
<h5>查询</h5> | |
<input type="text" ng-model="select"> | |
</div> | |
<div style="margin-left: 200px"> | |
<h5>排序</h5> | |
<select ng-model="Size"> | |
<option>--请选择--</option> | |
<option>100-200</option> | |
<option>200-300</option> | |
<option>300-400</option> | |
<option>400-500</option> | |
<option>600-700</option> | |
<option>700-800</option> | |
<option>800-900</option> | |
<option>900-1000</option> | |
</select> | |
</div> | |
<p></p> | |
<button style="background: deepskyblue; width: 100px; height: 50px" ng-click="addUser()">新增球员</button> | |
<br> | |
<table border="1px soild" cellspacing="0" cellpadding="10px" style="width: 800px; height: 300px; margin-top: 20px"> | |
<tr> | |
<th>姓名</th> | |
<th>位置</th> | |
<th>球号</th> | |
<th>票数</th> | |
</tr> | |
<tr ng-repeat="i in users| filter:{name:select} " ng-if="psSize(i.ps,Size)"> | |
<td>{{i.name}}</td> | |
<td>{{i.wz}}</td> | |
<td>{{i.size}}</td> | |
<td>{{i.ps}}</td> | |
</tr> | |
</table> | |
<table ng-if="myVar" border="1px soild" cellspacing="0" cellpadding="10px" style="margin: 20px auto"> | |
<tr> | |
<th> | |
添加球员 | |
</th> | |
</tr> | |
<tr> | |
<td>姓名:<input type="text" placeholder="请输入姓名" ng-model="name1"></td> | |
</tr> | |
<tr> | |
<td>位置:<input type="text" placeholder="请输入位置" ng-model="wz1"></td> | |
</tr> | |
<tr> | |
<td>球号:<input type="text" placeholder="请输入球号" ng-model="size1"></td> | |
</tr> | |
<tr> | |
<td>票数:<input type="text" placeholder="请输入票数" ng-model="ps1"></td> | |
</tr> | |
<tr align="center"> | |
<td><button ng-click="tijiao(name1,wz1,size1,ps1)">添加</button></td> | |
</tr> | |
</table> | |
</body> | |
</html> |
psc
最新推荐文章于 2024-04-09 22:08:33 发布