简单实现模糊搜索 可随意更改

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<!DOCTYPE html>
<html>
  
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>RunJS 演示代码</title>
    <script class="jquery library" src="/js/sandbox/jquery/jquery-1.8.2.min.js" type="text/javascript"></script>
        <style>
            *{
                margin:0;
                padding:0;
            }
            .wrap{
                margin:auto;
                width:300px;
            }
            table{
                width:300px;
                border:1px solid black;
                border-collapse:collapse;
            }
            th,td{
                border:1px solid black;
            }
        </style>
    <script>
        var data = {
            "rows": [{
                "name": "张三",
                "idn": "20114100000",
            }, {
                "name": "李四",
                "idn": "201556123000",
            }, {
                "name": "王五",
                "idn": "2012101221000",
            }, {
                "name": "赵六",
                "idn": "201191221000",
            }]
        };
            jQuery(function($){
                var tab = $("#tab"), txt = $("#txt");
                $(data.rows).each(function(i,dom){
                    var tr = $("<tr>");
                    for(var k in dom){
                        tr.append("<td>" + dom[k] + "</td>");
                    }
                    tab.append(tr);
                });
                txt.keyup(function(){
                    var me = $(this), v = me.val().replace(/^\s+|\s+$/g,"");
                    var trs = tab.find("tr:gt(0)");
                    if(v==""){
                        trs.filter(":hidden").show();
                    }else{
                        trs.hide().filter(":contains('"+me.val()+"')").show();
                    }
                });
            });
    </script>
</head>
  
<body>
        <div class="wrap">
            <input type="text" id="txt" />
        <table id="tab">
            <tr><th>name</th><th>idn</th></tr>
        </table>
    </div>
</body>
  
</html>

  

转载 https://zhidao.baidu.com/question/1640170088625879780.html

posted @   君宁天下  阅读(222)  评论(0编辑  收藏  举报
编辑推荐:
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
野生程序员真的是太难了,一刻也不敢停止学习
点击右上角即可分享
微信分享提示