输入框进行判断验证(弹出对话框,点击按钮查询并隐藏)
来源:互联网 发布:奇葩的淘宝收货人名字 编辑:程序博客网 时间: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>
<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
- 输入框进行判断验证(弹出对话框,点击按钮查询并隐藏)
- [ZK] messagebox 弹出对话框判断点击按钮
- js页面弹出一个带有输入框的弹窗,并判断点击的是确定还是取消按钮
- 点击按钮弹出对话框
- 点击按钮弹出对话框
- 点击按钮,弹出对话框
- 安卓点击Edittext弹出对话框实现操作(DatePicker,实现日期的输入)隐藏键盘
- 点击按钮弹出下载对话框
- 点击按钮弹出对话框提示
- Excel点击按钮弹出对话框
- java点击按钮弹出对话框
- Android点击按钮弹出对话框
- dojo点击按钮弹出对话框
- 如何用JS弹出“有输入框并带有是、否、取消按钮”的对话框。
- 点击按钮显示一个弹出框,点击一个弹出框以外的区域,隐藏弹出框
- 点击输入框弹出输入键盘,点击输入框外侧隐藏输入键盘
- MFC(6)点击按钮弹出新的对话框源码
- HTML点击按钮弹出对话框(仅代码)
- 邮件传输协议 SMTP 、POP3 、IMAP 和 Exchange 比较及联系?
- 系统的MVP购物车(二级购物车全)
- Object类的clone/equals/toString常用方法详解
- Linux下如何关闭防火墙,如何查看防火墙当前的状态
- ssh: Could not resolve hostname guard.: Name or service not known
- 输入框进行判断验证(弹出对话框,点击按钮查询并隐藏)
- Mysql读写分离
- echarts --流程图模型
- 如何转载别人文章(vyeah)
- Java基础总结第(6)天
- 并发设计模式之生产者-消费者模式
- opencv3.3.0+vs2015+cmake编译opencv x86
- 利用jad工具进行反编译
- 【深圳VS台湾】真正的无人驾驶还要等75年?在台湾已运行大半年(附台湾和深圳无人驾驶公交对比表)