【问题标题】:jQuery search filter - search within input boxesjQuery 搜索过滤器 - 在输入框中搜索
【发布时间】:2013-11-14 10:38:46
【问题描述】:

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

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

所以在这个小提琴中,如果我输入 mercedes 那么结果将显示 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();
});

任何帮助总是感激的

【问题讨论】:

    标签: jquery


    【解决方案1】:

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

    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;
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-15
      • 1970-01-01
      • 2017-10-30
      • 2013-07-30
      • 1970-01-01
      相关资源
      最近更新 更多