中文字幕av专区_日韩电影在线播放_精品国产精品久久一区免费式_av在线免费观看网站

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Angular如何實現搜索、過濾、批量刪除、添加、表單驗證功能

發布時間:2021-07-09 16:24:51 來源:億速云 閱讀:183 作者:小新 欄目:web開發

這篇文章將為大家詳細講解有關Angular如何實現搜索、過濾、批量刪除、添加、表單驗證功能,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。

具體代碼如下所示;

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
  <style>
    *{
      margin: 0;
      padding: 0;
    }
    .sspan{
      background: #28a54c;
      color: #fff;
      margin-left: 5px;
    }
    th,td{
      border: 1px solid #000;
      padding: 10px;
    }
    table{
      text-align: center;
      width: auto;
      border-collapse: collapse;
    }
    button{
      margin-top: 10px;
      margin-bottom: 10px;
    }
  </style>
</head>
<body ng-app="myapp" ng-controller="myCtrl">
  <div >
    <input type="text" placeholder="用戶名搜索" ng-model="yhmss"/>
    <input type="text" placeholder="手機號搜索" ng-model="sjhss"/>
    <select ng-model="Choicecity">
      <option>選擇城市</option>
      <option>北京</option>
      <option>上海</option>
      <option>天津</option>
      <option>重慶</option>
    </select>
    <select ng-model="Choicestate">
      <option>選擇狀態</option>
      <option>發貨</option>
      <option>已發貨</option>
    </select>
    <select ng-model="Choiceorder">
      <option>開始月份</option>
      <option>8</option>
      <option>9</option>
      <option>10</option>
    </select>
    -
    <select>
      <option>結束月份</option>
      <option>8</option>
      <option>9</option>
      <option>10</option>
    </select>
  </div>
  <button ng-click="tianjia()">新增訂單</button>
  <button ng-click="plsc()">批量刪除</button>
  <table>
    <thead>
    <tr >
      <th><input type="checkbox" ng-model="checkAll" ng-click="quan()"/></th>
      <th>id<button ng-click="sort('id')" class="sspan">排序</button></th>
      <th>商品名</th>
      <th>用戶名</th>
      <th>手機號</th>
      <th>價格<button ng-click="sort('price')" class="sspan">排序</button></th>
      <th>城市</th>
      <th>下單時間<button ng-click="sort('order')" class="sspan">排序</button></th>
      <th>狀態</th>
    </tr>
    </thead>
    <tbody>
    <tr ng-repeat="item in data|filter:{name:yhmss}|filter:{phone:sjhss}|filter:cityFun|filter:stateFun|filter:orderFun|orderBy:cc:dd">
      <td><input type="checkbox" ng-model="item.done"/></td>
      <td>{{$index+1}}</td>
      <td>{{item.commodity}}</td>
      <td>{{item.name}}</td>
      <td>{{item.phone}}</td>
      <td>{{item.price}}</td>
      <td>{{item.city}}</td>
      <td>{{item.order}}</td>
      <td ng-click="fahuo($index)"> {{item.state}} </td>
    </tr>
    </tbody>
  </table>
  <div ng-show="tj"  >
    <h2>添加</h2>
    <form name="registerForm" novalidate>
      <div id="email-group">
        <label for="email">E-mail:</label> <input type="email" class="form-control" ng-model="email" name="email" id="email" placeholder="請輸入電子郵箱..." required>
        <p>
          <span  ng-show=" registerForm.email.$invalid">
            <span ng-show="registerForm.email.$error.required">*請輸入郵箱</span> <span
              ng-show="registerForm.email.$error.email">*請輸入正確的email地址</span>
          </span>
        </p>
      </div>
      <div id="name-group">
        <label for="name">昵稱:</label> <input type="text" class="form-control" ng-model="name" name="name" id="name" placeholder="請輸入昵稱..." required>
        <p>
          <span  ng-show="registerForm.name.$invalid">
            <span ng-show="registerForm.name.$error.required">*請輸入姓名</span>
          </span>
        </p>
      </div>
      <div id="password-group">
        <label for="password">密碼:</label> <input type="password" class="form-control" ng-model="password"
                             ng-minlength="6" ng-maxlength="20" name="password" id="password"
                             placeholder="請輸入密碼..." required>
        <p>
          <span  ng-show="registerForm.password.$invalid">
            <span ng-show="registerForm.password.$error.minlength">*密碼長度不小于6</span>
            <span ng-show="registerForm.password.$error.maxlength">*密碼長度不超過20</span>
          </span>
        </p>
      </div>
      <div id="passwordagaingroup">
        <label for="passwordagain">再輸入一遍密碼:</label> <input type="password"
                                  class="form-control" ng-model="passwordagain" name="passwordagain"
                                  id="passwordagain" placeholder="請再輸一遍密碼..." required>
        <p>
          <span  ng-show="registerForm.password.$valid">
            <span ng-show="passwordagain!=password">*兩次密碼輸入不一致</span>
          </span>
        </p>
      </div>
      <button type="submit" class="btn btn-success" ng-click="tianjiapp()"
          ng-disabled="registerForm.email.$invalid || registerForm.name.$invalid || registerForm.password.$invalid || password != passwordagain">
        提交<span class="fa fa-arrow-right"></span>
      </button>
    </form>
  </div>
</body>
</html>
<script src="angular.js"></script>
  <script>
    var app = angular.module("myapp",[]);
    app.controller("myCtrl",function ($scope) {
      $scope.data = [
        {  commodity:"iPhone4",
          name:"張三",
          phone:151111111,
          price:4999,
          city:"北京",
          order:"8-1",
          state:"發貨",
          done:false
        },
        {  commodity:"小米6",
          name:"李四",
          phone:15222222,
          price:2999,
          city:"北京",
          order:"8-2",
          state:"發貨",
          done:false
        },
        {  commodity:"華為P9",
          name:"王五",
          phone:153333333,
          price:3999,
          city:"上海",
          order:"9-3",
          state:"已發貨",
          done:false
        },
        {  commodity:"OPPO R11",
          name:"趙六",
          phone:15444444,
          price:4999,
          city:"天津",
          order:"9-4",
          state:"已發貨",
          done:false
        },
        {  commodity:"ViVo",
          name:"錢七",
          phone:155555555,
          price:2999,
          city:"重慶",
          order:"10-4",
          state:"已發貨",
          done:false
        }
      ];
      $scope.Choicecity = "選擇城市";
      $scope.cityFun = function (item) {
        if($scope.Choicecity != "選擇城市"){
          if( item.city == $scope.Choicecity){
            return true;
          }else {
            return false;
          }
        }else {
          return true;
        }
      };
      $scope.Choicestate = "選擇狀態";
      $scope.stateFun = function (item) {
        if($scope.Choicestate != "選擇狀態"){
          if(item.state == $scope.Choicestate){
            return true;
          }else {
            return false;
          }
        }else {
          return true;
        }
      };
      $scope.pl = "已發貨";
      $scope.fahuo = function (index) {
        if($scope.data[index].state=="發貨"){
          $scope.data[index].state =$scope.pl;
        }
      };
      $scope.Choiceorder = "開始月份";
      $scope.orderFun = function (item) {
        if($scope.Choiceorder != "開始月份"){
          var arr = $scope.order.split("-");
          var min = arr[0];
          var max = arr[1];
          if(item.order >= min){
            return false;
          }else {
            return true;
          }
        }else {
          return true;
        }
      }
      $scope.quan = function () {
        if($scope.checkAll == true){
          for(var i = 0 ; i <$scope.data.length ; i++){
            $scope.data[i].done = true;
          }
        }else{
          for(var i = 0 ; i <$scope.data.length ; i++){
            $scope.data[i].done = false;
          }
        }
      };
      $scope.plsc = function () {
        for(var i = 0 ; i <$scope.data.length ; i++){
          if($scope.data[i].done == true){
            $scope.data.splice(i,1);
            i--;
          }
        }
      };
      $scope.tj = false;
      $scope.tianjia = function () {
        $scope.tj = true;
      };
      $scope.error = false;
      $scope.tijiaola = function () {
        if($scope.commoditys==null||$scope.names==null||
          $scope.commoditys<6||$scope.commoditys.length>20){
          $scope.error = true;
        }
      };
      $scope.dd = false;
      $scope.cc = "id";
      $scope.sort = function (couldm) {
        if($scope.cc == couldm ){
          $scope.dd =! $scope.dd;
        }
        $scope.cc = couldm;
      }
      $scope.tianjiapp = function () {
        $scope.data.push({commodity:$scope.email,name:$scope.name,phone:$scope.password})
      }
    })
  </script>

關于“Angular如何實現搜索、過濾、批量刪除、添加、表單驗證功能”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

蒙自县| 庐江县| 沾化县| 三门峡市| 南宫市| 肇源县| 确山县| 内丘县| 沐川县| 南康市| 通道| 威信县| 焦作市| 建昌县| 湘乡市| 天津市| 萍乡市| 合山市| 景宁| 咸宁市| 普安县| 南开区| 汶上县| 汉源县| 洛南县| 黔东| 岐山县| 清原| 出国| 承德县| 工布江达县| 东阳市| 讷河市| 车致| 河西区| 南江县| 永定县| 江阴市| 白沙| 封丘县| 乐都县|