<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script type="text/javascript" src="js/angular.js">
</script>
<script type="text/javascript">
var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope) {
$scope.shops = [{
"id": 10011120,
"name": "iphoneX",
"num": 99
}, {
"id": 10011121,
"name": "华为mate10",
"num": 20
}, {
"id": 10011122,
"name": "vivoR12",
"num": 55
}];
$scope.luru = function() {
var a=[];
if($scope.newId == "" || $scope.newId == null) {
a.push("ID不能为空")
alert("ID不能为空");
} else if(isNaN($scope.newId)) {
a.push("ID必须是数字")
alert("ID必须是数字");
}else if($scope.newId.length==8){
}
else
{
a.push("id必须为8位")
alert("id必须为8位")
}
if($scope.newName == "" || $scope.newName == null) {
a.push("产品不能为空")
alert("产品不能为空");
} else {
for(index in $scope.shops) {
if($scope.shops[index].name == $scope.newName) {
a.push("该资产已存在")
alert("该资产已存在");
}
}
}
if($scope.newNum == null || $scope.newNum == "") {
a.push("数量不能为空")
alert("数量不能为空");
} else if(isNaN($scope.newNum)) {
a.push("数量必须是数字")
alert("数量必须是数字")
}
//添加商品
if(a.length>0)
{
alert("请输入正")
}else{
var newShop = {
"id": parseInt($scope.newId),
"name": $scope.newName,
"num": parseInt($scope.newNum)
}
$scope.shops.push(newShop);
}
}
$scope.sou = function() {
var arr=[];
for(index in $scope.shops) {
if($scope.sousuo == $scope.shops[index].name) {
arr.push("搜到相关内容")
}
}
if(arr.length>0)
{
alert("搜到相关内容")
}else{
alert("未搜到相关内容")
}
}
});
</script>
</head>
<body ng-app="myApp" ng-controller="myCtrl">
<center>
资产搜索 : <input type="text" ng-model="sousuo" /><button ng-click="sou()">搜索</button>
<table border="1" cellspacing="0" cellpadding="10">
<tr>
<th>资产编号</th>
<th>资产名称</th>
<th>资产数量</th>
</tr>
<tr ng-repeat="shop in shops | filter : {'name':sousuo}">
<td>{{shop.id}}</td>
<td>{{shop.name}}</td>
<td>{{shop.num}}</td>
</tr>
</table>
<form style="margin-top: 50px;">
资产编号 <input type="text" value="" ng-model="newId" /><br /><br /> 资产名称 <input type="text" value="" ng-model="newName" /><br /><br /> 资产数量 <input type="text" value="" ng-model="newNum" /><br /><br />
<input type="submit" value="资产录入" ng-click="luru()" />
</form>
</center>
</body>
</html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script type="text/javascript" src="js/angular.js">
</script>
<script type="text/javascript">
var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope) {
$scope.shops = [{
"id": 10011120,
"name": "iphoneX",
"num": 99
}, {
"id": 10011121,
"name": "华为mate10",
"num": 20
}, {
"id": 10011122,
"name": "vivoR12",
"num": 55
}];
$scope.luru = function() {
var a=[];
if($scope.newId == "" || $scope.newId == null) {
a.push("ID不能为空")
alert("ID不能为空");
} else if(isNaN($scope.newId)) {
a.push("ID必须是数字")
alert("ID必须是数字");
}else if($scope.newId.length==8){
}
else
{
a.push("id必须为8位")
alert("id必须为8位")
}
if($scope.newName == "" || $scope.newName == null) {
a.push("产品不能为空")
alert("产品不能为空");
} else {
for(index in $scope.shops) {
if($scope.shops[index].name == $scope.newName) {
a.push("该资产已存在")
alert("该资产已存在");
}
}
}
if($scope.newNum == null || $scope.newNum == "") {
a.push("数量不能为空")
alert("数量不能为空");
} else if(isNaN($scope.newNum)) {
a.push("数量必须是数字")
alert("数量必须是数字")
}
//添加商品
if(a.length>0)
{
alert("请输入正")
}else{
var newShop = {
"id": parseInt($scope.newId),
"name": $scope.newName,
"num": parseInt($scope.newNum)
}
$scope.shops.push(newShop);
}
}
$scope.sou = function() {
var arr=[];
for(index in $scope.shops) {
if($scope.sousuo == $scope.shops[index].name) {
arr.push("搜到相关内容")
}
}
if(arr.length>0)
{
alert("搜到相关内容")
}else{
alert("未搜到相关内容")
}
}
});
</script>
</head>
<body ng-app="myApp" ng-controller="myCtrl">
<center>
资产搜索 : <input type="text" ng-model="sousuo" /><button ng-click="sou()">搜索</button>
<table border="1" cellspacing="0" cellpadding="10">
<tr>
<th>资产编号</th>
<th>资产名称</th>
<th>资产数量</th>
</tr>
<tr ng-repeat="shop in shops | filter : {'name':sousuo}">
<td>{{shop.id}}</td>
<td>{{shop.name}}</td>
<td>{{shop.num}}</td>
</tr>
</table>
<form style="margin-top: 50px;">
资产编号 <input type="text" value="" ng-model="newId" /><br /><br /> 资产名称 <input type="text" value="" ng-model="newName" /><br /><br /> 资产数量 <input type="text" value="" ng-model="newNum" /><br /><br />
<input type="submit" value="资产录入" ng-click="luru()" />
</form>
</center>
</body>
</html>