筛选 DIV 内容

Filter in DIV content

本文关键字:内容 DIV 筛选      更新时间:2023-09-26

我已经制作了这个jsFiddle,用于搜索/过滤我从XML响应中获得的div内容。但是我只为一个文本框做了。有人可以帮助我实施接下来的三个吗?

例如:

如果我输入pd001它会显示前 2 行,如果我键入粘贴,它应该到达并从当前可见列表而不是整个列表中过滤。

请帮帮我解决这个问题。

如果我

没有错,那么你必须尝试做的是 如果我根据pd001搜索 2 行并paste放在下一个文本框中,那么它应该只过滤这 2 行而不是整个网格。所有其他文本框的功能相同。实际上,您需要依赖项黑白文本框。

试试这个:

    $(".productid").filter(function () {
        $(this).parent().hide();
        return $(this).text().toLowerCase().indexOf(text0) != -1
    }).parent().show();
    $(".product:visible").filter(function () {
       $(this).parent().hide();
       return $(this).text().toLowerCase().indexOf(text1) != -1; 
    }).parent().show();
    $(".quantity:visible").filter(function () {
       $(this).parent().hide();
       return $(this).text().toLowerCase().indexOf(text2) != -1; 
    }).parent().show();
    $(".amount:visible").filter(function () {
       $(this).parent().hide();
       return $(this).text().toLowerCase().indexOf(text3) != -1; 
    }).parent().show();

演示:http://jsfiddle.net/fbC6w/4/

您只过滤了一列,它可能会对您有所帮助

$("#searchone , #searchtwo ,#searchthree ,#searchfour").bind("keyup", function() {
    var map = {
        '.productid': $("#searchone").val().toLowerCase(),
        '.product': $("#searchtwo").val().toLowerCase(),
        '.quantity': $("#searchthree").val().toLowerCase(),
        '.amount': $("#searchfour").val().toLowerCase()
    };
    $('div.new').each(function() {
        $(this).hide();
    });
    $('div.new').each(function() {
        var parent_div = this;
        $.each(map, function(key, value) {
            $(parent_div).find(key).filter(function() {
                if ($(this).text().toLowerCase().indexOf(value.toString()) != -1 && value != '') {
                    $(parent_div).show();
                }
            });
        });
    });
});​