个人信息表:(增删查)

<!DOCTYPE html>
<html>
 <head>
  <meta charset="UTF-8">
  <title></title>
  <script type="text/javascript" src="js/angular.js" ></script>
  <script>
   var app = angular.module("myApp",[]);
   app.controller("myCtrl",function($scope){
    $scope.paixu="-age";
    $scope.student = [{name:"张三",age:45,pinyin:"zhangsan",work:"总经理"},
                    {name:"李四",age:43,pinyin:"lisi",work:"设计师"},
                    {name:"王五",age:40,pinyin:"wangwu",work:"工程师"},
                    {name:"赵六",age:33,pinyin:"zhaoliu",work:"工程师"},
                    {name:"周七",age:31,pinyin:"zhouqi",work:"人事经理"}];
   
    $scope.tjflog=false;
    $scope.tj = function(){
     $scope.tjflog=true;
    }
    //添加
    $scope.bc = function(){
     if($scope.name==null||$scope.name==""){
      alert("名字不能为空");
     }else{
      if((isNaN($scope.age))){
       alert("年龄必须为数字");
      }else{
       if($scope.pinyin==null||$scope.pinyin==""){
        alert("拼音必填");
       }else{
        if($scope.work==null||$scope.work==""){
         alert("工作必须填");
        }else{
         $scope.student.push({name:$scope.name,age:parseInt($scope.age),pinyin:$scope.pinyin,work:$scope.work});
         $scope.name="";
         $scope.age="";
         $scope.pinyin="";
         $scope.work="";
         $scope.tjflog=false;
        }
       }
      }
     }
    }
    //删除
    $scope.sc=function(name){
     for (a in $scope.student) {
      if($scope.student[a].name==name){
       $scope.student.splice(a,1);
      }
     }
    }
    
    $scope.cx=function(){
      if($scope.newname==null||$scope.newname==""){
              alert("内容不能为空");
          }else{
               if($scope.newname=="傻逼"){
                $scope.newname="";
                alert("这是一个敏感字符");
               }else{
                var flog=false;
                for(a in $scope.student){
                 if($scope.student[a].name.indexOf($scope.newname)>=0){
                  var flog=true;
                 }
                }
                if(flog){
                 $scope.newnames=$scope.newname;
                }else{
                 alert("未查询到相关内容");
                 $scope.newnames="";
                }
               }
          }
    }
   });
  </script>
  
 </head>
 <body ng-app="myApp" ng-controller="myCtrl">
  <center>
   姓名查询条件<input type="text" ng-model="newname"/>
   <select ng-model="paixu">
    <option value="-age">按年龄正序</option>
    <option value="age">按年龄倒序</option>
   </select>
   <table border="1px soilde #000" width="400px">
        <tr>
             <th>姓名</th>
            <th>年龄</th>
            <th>拼音</th>
            <th>职位</th>
            <th>操作</th>
        </tr>
       <tr ng-repeat="student in student |filter:{'name':newnames} |orderBy:(paixu)">
           <td>{{student.name}}</td>
           <td>{{student.age}}</td>
           <td>{{student.pinyin}}</td>
           <td>{{student.work}}</td>
           <td><button ng-click="sc(student.name)" style="cursor: pointer;">删除</button></td>
       </tr>
   </table>
   <button style="margin-left: 100px;" ng-click="cx()">查询</button>
   <button ng-click="tj()">添加用户</button>
   <table ng-show="tjflog">
    <tr>
     <td>姓名</td>
     <td><input type="text" ng-model="name"/></td>
    </tr>
    <tr>
     <td>年龄</td>
     <td><input type="text" ng-model="age"/></td>
    </tr>
    <tr>
     <td>拼音</td>
     <td><input type="text" ng-model="pinyin"/></td>
    </tr>
    <tr>
     <td>职位</td>
     <td><input type="text" ng-model="work"/></td>
    </tr>
    <tr align="center">
     <td colspan="2"><button ng-click="bc()">保存</button></td>
    </tr>
   </table>
  </center>
 </body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值