Angular搜索 过滤 批量删除 添加 表单验证功能集锦(实例代码)
程序员文章站
2022-03-20 21:59:05
废话不多说了,直接给大家贴代码,具体代码如下所示;
废话不多说了,直接给大家贴代码,具体代码如下所示;
<!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搜索 过滤 批量删除 添加 表单验证功能集锦(实例代码),希望对大家有所帮助
下一篇: js设置随机切换背景图片的简单实例