输入框进行判断验证(弹出对话框,点击按钮查询并隐藏)

来源:互联网 发布:奇葩的淘宝收货人名字 编辑:程序博客网 时间:2024/05/23 19:02
<!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.goods= [{
id: 10011120,
name: "iPhone X",
num: 90
}, {
id: 10011121,
name: "华为mate10",
num: 20
}, {
id: 10011122,
name: "vivoR12",
num: 55
}];
//实现录入的判断
$scope.addGoods=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.goods){
if($scope.newName==$scope.goods[index].name){
flag=true;
}
}
if(flag){
alert("用户名重复");
flag2=false;
}else{
flag2=true;
}
if($scope.newNum==""|| $scope.newNum==null){
alert("数量不能为空");
flag3=false;
}else if(isNaN($scope.newNum)){
alert("数量必须为数字");
flag3=false;
}else{
flag3=true;
}
if(flag1 && flag2 && flag3){
//添加
$scope.goods.push({
id:$scope.newId,
name:$scope.newName,
num:$scope.newNum

});
}
}
//查询
$scope.selectName=function(){
var flag=false;
$scope.selectShow="";
for(index in $scope.goods){
if($scope.chaxun==$scope.goods[index].name){
flag=true;
}
}
if($scope.chaxun==null || $scope.chaxun==""){
alert("输入框不能为空");
$scope.selectShow="";
}else if(flag){
alert("商品存在");
$scope.selectShow=$scope.chaxun;
}else{
alert("商品不存在");
$scope.selectShow=null;
}
}
  });
  </script>
</head>
<body ng-app="myApp" ng-controller="myCtrl">
<h3>资产登记</h3>
资产搜索:<input type="text" placeholder="请输入查询结果"  ng-model="chaxun"/>
<button ng-click="selectName()">搜索</button>
<table border="1" cellpadding="10" cellspacing="0">
<tr>
<th>资产编号</th>
<th>资产名称</th>
<th>资产数量</th>
</tr>
<tr ng-repeat="g in goods | filter:selectShow" align="center">
<td>{{g.id}}</td>
<td>{{g.name}}</td>
<td>{{g.num}}</td>
</tr>
</table>
<form>

资产编号:<input type="text" ng-model="newId" /><br />
资产名称:<input type="text" ng-model="newName" /><br />
资产数量:<input type="text" ng-model="newNum" /><br />
       <button ng-click="addGoods()">添加</button>
</form>
</body>
</html>
阅读全文
0 0
原创粉丝点击