第二周的

<!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>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值