jQuery搜索过滤器 - 在输入框中搜索 [英] jQuery search filter - search within input boxes

查看:51
本文介绍了jQuery搜索过滤器 - 在输入框中搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是jQuery搜索过滤器,效果很好。但是我也需要在输入框中搜索和过滤。输入框都是类型文本,我需要像其他表格列中的文本一样使用值。

I am using a jQuery search filter and it works well. However I also need to search and filter within the input boxes too. The input boxes are all type text and I need to use the value like the text within the other table columns.

我创建了一个小提琴,
http://jsfiddle.net/ktcle/Jf6q5/

I have created a fiddle, http://jsfiddle.net/ktcle/Jf6q5/

所以在这个小提琴中,如果我键入梅赛德斯,那么结果将显示梅赛德斯

So in this fiddle if I type mercedes then the result would show mercedes

$("#searchInput").keyup(function () {

var data = this.value.split(" ");
var jo = $("#fbody").find("tr");
if (this.value == "") {
    jo.show();
    return;
}

jo.hide();

jo.filter(function (i, v) {
    var $t = $(this);
    var matched = true;
    for (var d = 0; d < data.length; ++d) {
        if (data[d].match(/^\s*$/)) {
            continue;
        }

        var regex = new RegExp(data[d].toLowerCase());
        if ($t.text().toLowerCase().replace("").match(regex) === null) {
            matched = false;
        }
    }
    return matched;
})

.show();
});

任何帮助总是赞赏

推荐答案

我在这个小提琴中编辑了你的剧本:

i edited your script in this fiddle :

http://jsfiddle.net/Jf6q5/14/

jo.filter(function (i, v) {
    var $t = $(this);
    var matched = true;
    for (var d = 0; d < data.length; ++d) {
        var value = "";
        $t.find("td").each(function(){
            var _td = $(this);
            value += _td.text() + _td.find("input").val();
        });
        if (data[d].match(/^\s*$/)) {
            continue;
        }

        var regex = new RegExp(data[d].toLowerCase());
        if (value.toLowerCase().replace("").match(regex) === null) {
            matched = false;
        }
    }
    return matched;
});

这篇关于jQuery搜索过滤器 - 在输入框中搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆