angularjs实现模糊查询添加程序

<!DOCTYPE html>
<html>
 <head>
  <meta charset="UTF-8">
  <title>第三周周考</title>
  <script type="text/javascript" src="../angularjs/angular-route.js" ></script>
  <script type="text/javascript" src="../angularjs/angular.js" ></script>
  
  <style>
   
   table tr:nth-child(even){
    background-color:#7C7CC5;
   }
   table tr:nth-child(odd){
    background-color:#FFEB87;
   }
  </style>
  
  <script type="text/javascript">
  
  </script>
  <script type="text/javascript">
   var app=angular.module("myApp",[]);
   app.controller("myCtrl",function($scope){
    var date=new Date();
    $scope.list=[
     {
      name:"云南白药",
      num:100,
      address:"云南",
      price:19.9,
      time:date
     },
     {
      name:"999感冒灵",
      num:30,
      address:"北京",
      price:12.5,
      time:date

     },
     {
      name:"感康",
      num:20,
      address:"河北",
      price:16.6,
      time:date
     }
    ];
    
    //实现删除的功能
    $scope.del=function(name){
     for(index in $scope.list){
      if(name==$scope.list[index].name){
       if(window.confirm("确定要删除用户吗?")){
        $scope.list.splice(index,1);
        alert("删除成功");
       }else{
        
       }
      }
     }
    };
    
    //按照要求进行排序
    $scope.bian;
    $scope.chan=function(){
     if($scope.bian=="num"){
      $scope.orderFlag="";
      $scope.orderLine="num";
     }else if($scope.bian=="-num"){
      $scope.orderFlag="-";
      $scope.orderLine="num";
     }else if($scope.bian=="time"){
      $scope.orderFlag="";
      $scope.orderLine="time";
     }else if($scope.bian=="-time"){
      $scope.orderFlag="-";
      $scope.orderLine="time";
     }
    };

    $scope.isShow=false;
    $scope.btn=function(){
     if($scope.isShow){
      $scope.isShow=false;
     }else{
      $scope.isShow=true;
     }
    }
    
    //添加数据
    $scope.newname="";
    $scope.newnum="";
    $scope.newaddress="";
    $scope.newprice="";
    $scope.addList=function(){
     var lists={
      name:$scope.newname,
      num:parseInt($scope.newnum),
      address:$scope.newaddress,
      price:$scope.newprice,
      time:new Date()
     };
     $scope.list.push(lists);
    }
   });
  </script>
 </head>
 <body ng-app="myApp" ng-controller="myCtrl">
  <!--进行页面的布局-->
  <center>
   <input type="text" placeholder="输入关键字搜索" ng-model="search" />
   
   <select ng-change="chan()" ng-model="bian">
    <option value="">--请选择--</option>
    <option value="num">按货物数量正序排列</option>
    <option value="-num">按货物数量逆序排列</option>
    <option value="time">按入库时间正序排列</option>
    <option value="-time">按入库时间逆序排列</option>
   </select>
   
   <button ng-click="btn()">入库</button>
   <br />
   <br />
   <table border="1px solid red" cellpadding="10" cellspacing="0" id="table1">
    <tr style="background-color:#CD9A5B;">
     <th>货物名称</th>
     <th>货物数量</th>
     <th>货物产地</th>
     <th>货物单价</th>
     <th>货物入库时间</th>
     <th>操作</th>
    </tr>
    <tr ng-repeat="l in list | filter:{name:search} | orderBy:(orderFlag+orderLine)" >
     <td>{{l.name}}</td>
     <td>{{l.num}}</td>
     <td>{{l.address}}</td>
     <td>{{l.price | currency:"¥:"}}</td>
     <td>{{l.time | date:"yyyy-MM-dd HH:mm:ss"}}</td>
     <td><button ng-click="del(l.name)">删除</button></td>
    </tr>
   </table>
   <br /><br />
   <div style="width: 300px;" ng-show="isShow">
    <h3>入库操作</h3>
    商品名称:<input type="text"placeholder="请输入商品名称" ng-model="newname"/><br/>
    商品数量:<input type="text"placeholder="请输入商品数量" ng-model="newnum"/><br/>
    商品产地:<input type="text"placeholder="请输入商品产地" ng-model="newaddress"/><br/>
    商品价格:<input type="text"placeholder="请输入商品价格" ng-model="newprice"/><br/>
    <button ng-click="addList()">添加</button>
   </div>
  </center>
 </body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值