layui实现table表格的“关键字搜索”功能

  1     $('#searchBtn').on('click',function(){
  2         var type = $(this).data('type');
  3         active[type] ? active[type].call(this) : '';
  4     });
  5     // 点击获取数据
  6     var  active = {
  7  getInfo: function () {
 88             var fileName=$('#fileName').val();
 89             // var startTime=$('#startTime').val();
 90             // var endTime=$('#endTime').val();
 91             var timeRange=$('#timeRange').val();
 92             if ($('#fileName').val()||$('#md5Name').val()||$('#timeRange').val()) {
 93                 var index = layer.msg('查询中,请稍候...',{icon: 16,time:false,shade:0});
 94                 setTimeout(function(){
 95                     table.reload('flinklist', {
 96                         where: {
 97                             'fileName':fileName,
 98                             'timeRange':timeRange
 99                         }
100                     });
101                     layer.close(index);
102                 },800);
103             } else {
104                 table.reload('flinklist', {where: {
105                         'fileName':fileName,
106                         'timeRange':timeRange
107                     }});
108                 table.reload('')
109             }
110         },
111     };
1  //html代码
2 <a class="layui-btn search_btn "  id="searchBtn"  data-type="getInfo" style="margin-left: 15px;">查询</a>
 1 当键盘按键弹起时自动进行搜索:
 2     $('#search_term').keyup(function () {
 3         // 1.获得搜索框的值;
 4         // 2.判断如果有值。layer.msg()
 5         // 3.定义延时函数,8s后刷新表格,并传递参数;
 6         // 4.关闭layer.msg()
 7         var keyWord=$('#search_term').val();
 8         if($('#search_term')!=''){
 9             var index=layer.msg('正在查询请稍后',{
10                 icon:2,
11                 title:'提示',
12                 time:false
13             })
14             setTimeout(function () {
15                 table.reload('getUser',{
16                     where:{
17                         pageSize:15,
18                         currentPage:1,
19                         keyWords:keyWord
20                     }
21                 })
22             },800);
23         }else{
24             getAllUser();
25         }
26     });
原文地址:https://www.cnblogs.com/yangguoe/p/8953830.html