查询alter提醒和表单判断

<head>
<meta charset="utf-8" />
<title>周考3</title>
<style type="text/css">



</style>
<script type="text/javascript" src="js/angular.js" ></script>
<script>
var app=angular.module("myApp",[]);
app.controller("myCtril",function($scope){
$scope.shops=[{
id:10011120,
name:"iphonx",
jg:99},
{
id:10011121,
name:"华为",
jg:20},
{
id:10011122,
name:"vivo",
jg:55},

];
//表单查询
//添加
//isNaN 判断是不是数字
$scope.addshop=function() {
var flag1=false;
var flag2=false;
var flag3=false;
if($scope.newid=="" || $scope.newid==null){
alert("id不能为空");
flag1=false;
}else if(isNaN($scope.newid)){
alert("id必须是数字");
flag1=false;
}else if($scope.newid.length !=8){
alert("id必须是8位");
flag1=false;
}else{
flag1=true;
}
var flag=false;
for(index in $scope.shops){
if($scope.newname == $scope.shops[index].name){
flag=true;
}
}
if(flag){
alert("用户名重复");
flag2=false;
}else{
flag2=true;
}
if($scope.newjg=="" || $scope.newjg==null){
alert("价格不能为空");
flag3=false;
}else if(isNaN($scope.newjg)){
alert("价格必须是数字");
flag3=false;
}else{
flag3=true;
}
if(flag1 && flag2 && flag3){
//添加
$scope.shops.push({
id:$scope.newid,
name: $scope.newname,
jg:$scope.newjg
});
}
}
//查询
$scope.show="";
$scope.sou=function(){
if($scope.show==null || $scope.show==""){
alert("搜索框不能为空");
}
for(shop in $scope.shops){
if($scope.show==$scope.shops[shop].name){
alert("搜索到内容");
break;
}else{
alert("为搜索到内容");
break;
}
}
}
});
</script>
</head>
<body ng-app="myApp" ng-controller="myCtril">
<h3>资产登记</h3>
<table border="1" cellpadding="0" cellspacing="0" width="300px">
<thead>
<tr>
<th>资产编号</th>
<th>资产名称</th>
<th>资产数量</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="shop in shops | filter:{name:show}" >
<td align="center">{{shop.id}}</td>
<td align="center">{{shop.name}}</td>
<td align="center">{{shop.jg}}</td>
</tr>
</tbody>
</table>
<br><br>
资产编号:<input type="text" ng-model="newid"/><br />
资产名称:<input type="text" ng-model="newname"/><br />
资产数量:<input type="text" ng-model="newjg"/><br /><br />
<button style="margin-left: 100px" ng-click="addshop()">资产录入</button><br><br>
资产搜索:<input type="text" ng-model="show"/><br/><br/>
<button style="margin-left: 100px" ng-click="sou()">搜索</button>
</body>

猜你喜欢

转载自blog.csdn.net/wsj19970717/article/details/78847196