Angular搜索 过滤 批量删除 添加 表单验证功能集锦(实例代码)


Posted in Javascript onOctober 25, 2017

废话不多说了,直接给大家贴代码,具体代码如下所示;

<!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 style="width: 1000px">
    <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 style="background: #4404">
      <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" style="margin-left: 200px" >
    <h1>添加</h1>
    <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 style="color: red" 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 style="color: red" 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 style="color: red" 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 style="color: red" 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搜索 过滤 批量删除 添加 表单验证功能集锦(实例代码),希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对三水点靠木网站的支持!

Javascript 相关文章推荐
Add a Picture to a Microsoft Word Document
Jun 15 Javascript
jQuery AJAX 调用WebService实现代码
Mar 24 Javascript
JavaScript实现简单图片翻转的方法
Apr 17 Javascript
JQuery Mobile实现导航栏和页脚
Mar 09 Javascript
从零学习node.js之利用express搭建简易论坛(七)
Feb 25 Javascript
Bootstrap fileinput组件封装及使用详解
Mar 10 Javascript
ES6字符串模板,剩余参数,默认参数功能与用法示例
Apr 06 Javascript
Angularjs 事件指令详细整理
Jul 27 Javascript
js禁止表单重复提交
Aug 29 Javascript
vue 文件目录结构详解
Nov 24 Javascript
react-native封装插件swiper的使用方法
Mar 20 Javascript
Vue3配置axios跨域实现过程解析
Nov 25 Vue.js
js插件实现图片滑动验证码
Sep 29 #Javascript
使用Bootstrap和Vue实现用户信息的编辑删除功能
Oct 25 #Javascript
详解JSONObject和JSONArray区别及基本用法
Oct 25 #Javascript
详解HTML5 使用video标签实现选择摄像头功能
Oct 25 #Javascript
vue 数组和对象不能直接赋值情况和解决方法(推荐)
Oct 25 #Javascript
JS使用tofixed与round处理数据四舍五入的区别
Oct 25 #Javascript
javascript计算对象长度的方法
Oct 25 #Javascript
You might like
PHP的面试题集,附我的答案和分析(一)
2006/11/19 PHP
php skymvc 一款轻量、简单的php
2011/06/28 PHP
利用ajax和PHP实现简单的流程管理
2017/03/23 PHP
PHP实现的MD5结合RSA签名算法实例
2017/10/07 PHP
tp5.1 框架查询表达式用法详解
2020/05/25 PHP
Javascript写入txt和读取txt文件示例
2014/02/12 Javascript
Javascript模拟加速运动与减速运动代码分享
2014/12/11 Javascript
有关Promises异步问题详解
2015/11/13 Javascript
JavaScript中的对象和原型(一)
2016/08/12 Javascript
AngularJS解决ng-if中的ng-model值无效的问题
2017/06/21 Javascript
基于jQuery实现的Ajax 验证用户名唯一性实例代码
2017/06/28 jQuery
vue利用v-for嵌套输出多层对象,分别输出到个表的方法
2018/09/07 Javascript
JavaScript事件概念详解(区分静态注册和动态注册)
2021/02/05 Javascript
[39:18]完美世界DOTA2联赛PWL S3 Forest vs LBZS 第二场 12.17
2020/12/19 DOTA
python分割文件的常用方法
2014/11/01 Python
Python发送email的3种方法
2015/04/28 Python
解决python nohup linux 后台运行输出的问题
2018/05/11 Python
Python将多个list合并为1个list的方法
2018/06/27 Python
对python实现模板生成脚本的方法详解
2019/01/30 Python
python web框架 django wsgi原理解析
2019/08/20 Python
基于Python实现扑克牌面试题
2019/12/11 Python
Python3批量创建Crowd用户并分配组
2020/05/20 Python
keras导入weights方式
2020/06/12 Python
tensorflow之读取jpg图像长和宽实例
2020/06/18 Python
关于Theano和Tensorflow多GPU使用问题
2020/06/19 Python
python线程里哪种模块比较适合
2020/08/02 Python
CSS3只让背景图片旋转180度的实现示例
2021/03/09 HTML / CSS
关于HTML5你必须知道的28个新特性,新技巧以及新技术
2012/05/28 HTML / CSS
Myprotein西班牙官网:欧洲第一大运动营养品牌
2020/02/24 全球购物
董事长秘书岗位职责
2013/11/29 职场文书
药品促销活动方案
2014/02/14 职场文书
求职简历自我评价范例
2014/03/12 职场文书
石油工程专业毕业生求职信
2014/04/13 职场文书
二十年同学聚会致辞
2015/07/28 职场文书
老舍《猫》教学反思
2016/02/17 职场文书
如何使用Python对NetCDF数据做空间相关分析
2021/04/21 Python