文章标题 球员表格(增 查 排序)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="jquery-2.1.0.js"></script>
    <script src="angular.js"></script>
    <style>

        .even{
           background-color: darkgray;
        }
        .odd{
            background-color: honeydew;
        }
        .d{
            background-color: darkgray;
        }


      .a{ width: 800px}
        .b{width: 600px}
    </style>
    <script>
        $(function(){
            $("thead tr").addClass("first");
            $("tbody tr:even").addClass("even");
            $("tbody tr:odd").addClass("odd");
            $("thead tr").addClass("first");
     $("#tr th").mousedown(function () {
         $(this).addClass("d")
     });
     $("#tr th").mouseup(function () {
         $(this).removeClass("d")
     });

        });
    </script>
    <script>

        var app=angular.module("myAPP",[]);
        app.controller("myCtrl",function ($scope) {
            $scope.users=[
                {"id":1,"name":"张三","weizhi":"控球后卫","qiuhao":11,"piao":999},
                {"id":2,"name":"李四","weizhi":"大前锋","qiuhao":21,"piao":888},
                {"id":3,"name":"王五","weizhi":"小前锋","qiuhao":23,"piao":777},
                {"id":3,"name":"赵六","weizhi":"中锋","qiuhao":10,"piao":666},
                {"id":3,"name":"周七","weizhi":"得分后卫","qiuhao":1,"piao":555}
            ];



                $scope.name = "";
                $scope.weizhi = "";
                $scope.qiuhao = "";
                $scope.piao = "";
            $scope.sub = function () {

            }



                $scope.suba = function(){

                        var flag = true;
                        //拿到各个输入框的值
                        if($scope.name==""||$scope.name==null){
                            alert("用户名不能为空");
                            flag = false;
                        }
                        if($scope.weizhi==""||$scope.weizhi==null){
                            alert("位置不能为空");
                            flag = false;
                        }
                        if($scope.qiuhao==""||$scope.qiuhao==null){
                            alert("球号不能为空");
                            flag = false;
                        }
                        if($scope.piao==""||$scope.piao==null){
                            alert("票不能为空");
                            flag = false;

                        }



                    var newUser = {

                        name:$scope.name,
                        weizhi:$scope.weizhi,
                        qiuhao:$scope.qiuhao,
                        piao:$scope.piao
                    }
                    //添加新用户.
                    $scope.users.push(newUser);
                }
   $scope.order="-piao"
          /*  //自定义过滤器
            app.filter("myFilter",function(){
                return function(text){
                    if(text.indexOf("敏感字符")>=0){
                        //替换字符串
                        return text.replace(/敏感字符/g,"****");
                    }else{
                        return text;
                    }
                }
            });*/

        });
    </script>
</head>
<body ng-app="myAPP" ng-controller="myCtrl">
<center>
<div>

  <table>

      <tr>
          <td>查询</td>
          <td><input ng-model="search" type="text" size="10"/></td>
          <td>排序</td>

          <td> <select ng-model="order">
              <option value="-piao">票数倒数</option>
              <option value="+piao">票数整数</option>
          </select></td>
      </tr>
  </table>


</div><br><br/>
    <input style="background-color: lightseagreen; margin-bottom: 50px;" type="button" ng-click="suba()" value="新增球员" />


    <div>
        <table class="a" border="1" cellpadding="10" cellspacing="0">

            <thead>
            <tr id="tr">
                <th>姓名</th>
                <th>位置</th>
                <th>球号</th>
                <th>票数</th>

            </tr>
            </thead>
            <tbody>
            <tr  ng-repeat="user in users | filter:{'name':search} | filter:search | orderBy:order">
                <td>{{user.name}}</td>
                <td>{{user.weizhi}}</td>
                <td>{{user.qiuhao}}</td>
                <td>{{user.piao}}</td>

            </tr>
            </tbody>
        </table>
        </table>
    </div>



   <br><br/>
    <div>
        <form action="">
            <table class="b" border="1" cellspacing="0" cellpadding="10">
                <tr>
                    <th>用户名:</th>
                    <td><input ng-model="name" placeholder="请输入用户名" /></td>
                </tr>
                <tr>
                    <th>位置:</th>
                    <td><input ng-model="weizhi" placeholder="请输入位置" /></td>
                </tr><tr>
                <th>球号:</th>
                <td><input ng-model="qiuhao" placeholder="请输入球号" /></td>
            </tr><tr>
                <th>票数:</th>
                <td><input ng-model="piao" placeholder="请输入票数" /></td>
            </tr>

                <tr align="center">
                    <td colspan="2"><button style="background-color: lightseagreen" type="button" ng-click="suba()">新增球员</button></td>
                </tr>
            </table>
        </form>
    </div>




</center>
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
layui是一款优秀的前端UI框架,其中包含了丰富的组件,包括表格组件,可以用来实现表格删改功能。 首先,在HTML页面中引入layui的相关文件: ```html <link rel="stylesheet" href="layui/css/layui.css"> <script src="layui/layui.js"></script> ``` 然后,在页面中添加一个表格: ```html <table class="layui-table" lay-filter="test"> <thead> <tr> <th>ID</th> <th>姓名</th> <th>年龄</th> <th>操作</th> </tr> </thead> <tbody> <tr> <td>001</td> <td>张三</td> <td>20</td> <td> <button class="layui-btn layui-btn-xs layui-btn-normal">编辑</button> <button class="layui-btn layui-btn-xs layui-btn-danger">删除</button> </td> </tr> <tr> <td>002</td> <td>李四</td> <td>22</td> <td> <button class="layui-btn layui-btn-xs layui-btn-normal">编辑</button> <button class="layui-btn layui-btn-xs layui-btn-danger">删除</button> </td> </tr> </tbody> </table> ``` 接着,使用JavaScript代码初始化表格: ```javascript layui.use('table', function(){ var table = layui.table; //执行渲染 table.render({ elem: '#test', //绑定元素 cols: [[ //标题栏 {field: 'id', title: 'ID'}, {field: 'name', title: '姓名'}, {field: 'age', title: '年龄'}, {fixed: 'right', title:'操作', toolbar: '#barDemo'} ]], data: [ //数据 {id: '001', name: '张三', age: 20}, {id: '002', name: '李四', age: 22} ] }); }); ``` 最后,添加表格删改功能: ```javascript layui.use(['table', 'layer'], function(){ var table = layui.table; var layer = layui.layer; //监听工具条 table.on('tool(test)', function(obj){ var data = obj.data; //获取当前行数据 var layEvent = obj.event; //获取lay-event对应的值 if(layEvent === 'edit'){ //编辑 layer.open({ type: 2, title: '编辑', content: 'edit.html?id=' + data.id, area: ['500px', '400px'], btn: ['保存', '取消'], yes: function(index, layero){ //保存数据的逻辑 layer.close(index); //关闭弹窗 } }); } else if(layEvent === 'delete'){ //删除 layer.confirm('确定要删除吗?', function(index){ //删除数据的逻辑 layer.close(index); //关闭弹窗 }); } }); //监听提交 form.on('submit(add)', function(data){ //添加数据的逻辑 layer.closeAll(); return false; }); }); ``` 以上代码实现了一个简单的表格删改功能,你可以根据自己的需求来修改。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值