jQuer实时监控input对table进行筛选

  记得之前写过一个预约表格~~~~~比这个更难,一大串前端js~~~忘了~~~好记性不如烂笔头~~记录下,既帮助别人,也帮助本身~~~前端

实现思路~经过.on监听input标签的内容变化,经过this获取到val,经过.hide隐藏未匹配标签~~~大体这样jquery

  • oninput是HTML5的标准事件
  • 可以检测textarea,input:text,input:password和input:search这几个元素的内容变化,
  • 在内容修改后当即被触发,不像onchange事件须要失去焦点才触发
  • oninput事件在IE9如下版本不支持,须要使用IE特有的onpropertychange事件替代
  • 使用jQuery库的话直接使用on同时绑定这两个事件便可。
<input type="text" class="form-control" id="item_keyword"
                                       name="item_keyword"  placeholder="请输入关键字查找">
input代码
    <script src="/static/js/jquery-3.1.1.min.js"></script>
    <script >
    /* 实时搜索框,及点击按钮全选\取消*/
            $('#item_keyword').on('input propertychange', function() {
                console.log( $(this).val());
                $('table tbody tr').hide()
             .filter(":contains('" + ($(this).val()) + "')")
             .show();
            });
    </script>
JS代码
相关文章
相关标签/搜索