Web页面table表格,实现快速筛选

谁用谁知道

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>

    <!--jQuery-->
    <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>

    <style>
        table {
            border:0;
        }
        p {
            font:normal 12px/17px Arial;
        }
        td {
            font:normal 12px/17px Arial;
            padding:2px;
            width:100px;
        }
        th {
            font:bold 12px/17px Arial;
            text-align:left;
            padding:4px;
            border-bottom:1px solid #333;
            width:100px;
        }
        .even {
            background:#FFF38F;
        }
        /* 偶数行样式*/
        .odd {
            background:#FFFFEE;
        }
        /* 奇数行样式*/
        .selected {
            background:#FF6500;
            color:#fff;
        }
    </style>
</head>
<body>
    <p> 
        <br> 筛选: 
        <input id="filterName" name="filterName"> 
        <span class="search">搜索</span> 
        <br> 
    </p>

    <table>
        <thead>
        <tr><th>姓名</th><th>性别</th><th>暂住地</th></tr>
        </thead>
        <tbody>
        <tr><td>SYJ</td><td>男</td><td>河北秦皇岛市</td></tr>
        <tr><td>李四</td><td>女</td><td>北京北京市</td></tr>
        <tr><td>王五</td><td>男</td><td>河北秦皇岛市</td></tr>
        <tr><td>赵六</td><td>男</td><td>河北唐山市</td></tr>
        <tr><td>张三</td><td>男</td><td>内蒙古呼和浩特市</td></tr>
        <tr><td>楠楠</td><td>女</td><td>内蒙古包头市</td></tr>
        <tr><td>贝贝</td><td>男</td><td>北京北京市</td></tr>
        <tr><td>西西</td><td>女</td><td>河北秦皇岛市</td></tr>
        <tr><td>冬冬</td><td>男</td><td>东北辽宁省</td></tr>
        </tbody>
    </table>
    
    <!--排序函数-->
    <script type="text/javascript">
        $(function() {
            $('.search').on('click', function() {
                // console.log($('#filterName').val());
                $('table tbody tr').hide()
                    .filter(":contains('" + ($('#filterName').val()) + "')")
                    .show();
            })
        })
    </script>
</body>
</html> 

    原文作者:紫薯馍馍
    原文地址: https://blog.csdn.net/u012972294/article/details/125888231
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞