当前位置: 移动技术网 > IT编程>开发语言>JavaScript > JQuery表格内容过滤的实现方法

JQuery表格内容过滤的实现方法

2018年09月14日  | 移动技术网IT编程  | 我要评论

代码如下:


[html]
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "https://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="https://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>jquery表格内容过滤</title>
<style type="text/css">
table{ border:0;border-collapse:collapse;}
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>
<!--   引入jquery -->
<script src="jquery-1.5.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
  $(function(){
       $("#filtername").keyup(function(){
          $("table tbody tr")
                    .hide()
                    .filter(":contains('"+( $(this).val() )+"')")
                    .show();
       }).keyup();
  })
</script>
</head>
<body>
    <p> <br/> 筛选: <input id="filtername" name="filtername" /> <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>
</body>
</html>

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网