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 相关文章推荐
仿中关村在线首页弹出式广告插件(jQuery版)
May 03 Javascript
javascript操作table(insertRow,deleteRow,insertCell,deleteCell方法详解)
Dec 16 Javascript
JS中创建函数的三种方式及区别
Mar 13 Javascript
浅谈JavaScript的闭包函数
Dec 08 Javascript
JavaScript仿聊天室聊天记录
Dec 27 Javascript
bootstrap日期控件问题(双日期、清空等问题解决)
Apr 19 Javascript
JavaScript取得gridview中获取checkbox选中的值
Jul 24 Javascript
详解vue移动端日期选择组件
Feb 22 Javascript
vue2.0 axios跨域并渲染的问题解决方法
Mar 08 Javascript
微信小程序页面间跳转传参方式总结
Jun 13 Javascript
jQuery操作动画完整实例分析
Jan 10 jQuery
JavaScript前端面试扁平数据转tree与tree数据扁平化
Jun 14 Javascript
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
PHP4和PHP5共存于一系统
2006/11/17 PHP
php将数据库中所有内容生成静态html文档的代码
2010/04/12 PHP
php处理json时中文问题的解决方法
2011/04/12 PHP
php7 图形用户界面GUI 开发示例
2020/02/22 PHP
在视频前插入广告
2006/11/20 Javascript
获取服务器传来的数据 用JS去空格的正则表达式
2012/03/26 Javascript
jQuery-onload让第一次页面加载时图片是淡入方式显示
2012/05/23 Javascript
javascript数组的使用
2013/03/28 Javascript
jquery 单引号和双引号的区别及使用注意
2013/07/31 Javascript
JS实现随机数生成算法示例代码
2013/08/08 Javascript
js setTimeout 常见问题小结
2013/08/13 Javascript
jquery中get,post和ajax方法的使用小结
2014/02/04 Javascript
javascript中eval和with用法实例总结
2015/11/30 Javascript
使用vue.js开发时一些注意事项
2016/04/27 Javascript
js 实现获取name 相同的页面元素并循环遍历的方法
2017/02/14 Javascript
ES6中module模块化开发实例浅析
2017/04/06 Javascript
微信小程序与php 实现微信支付的简单实例
2017/06/23 Javascript
Angular 2父子组件数据传递之局部变量获取子组件其他成员
2017/07/04 Javascript
js实现input密码框显示/隐藏功能
2020/09/10 Javascript
javascript实现点亮灯泡特效示例
2019/10/15 Javascript
微信小程序swiper使用网络图片不显示问题解决
2019/12/13 Javascript
windows下cx_Freeze生成Python可执行程序的详细步骤
2018/10/09 Python
python 模拟贷款卡号生成规则过程解析
2019/08/30 Python
6行Python代码实现进度条效果(Progress、tqdm、alive-progress​​​​​​​和PySimpleGUI库)
2020/01/06 Python
tensorflow 2.0模式下训练的模型转成 tf1.x 版本的pb模型实例
2020/06/22 Python
Python如何爬取b站热门视频并导入Excel
2020/08/10 Python
利用Python如何制作贪吃蛇及AI版贪吃蛇详解
2020/08/24 Python
Python 使用Opencv实现目标检测与识别的示例代码
2020/09/08 Python
IE下实现类似CSS3 text-shadow文字阴影的几种方法
2011/05/11 HTML / CSS
使用css3实现的tab选项卡代码分享
2014/12/09 HTML / CSS
二年级体育教学反思
2014/01/15 职场文书
维稳工作承诺书
2015/01/20 职场文书
幼儿园六一主持词开场白
2015/05/28 职场文书
总结python多进程multiprocessing的相关知识
2021/06/29 Python
为什么MySQL 删除表数据 磁盘空间还一直被占用
2021/10/16 MySQL
Python IO文件管理的具体使用
2022/03/20 Python