2012-08-16 74 views
4

我製作了this jsFiddle用於搜索/篩選我從XML響應中獲得的div內容。但我已經完成了一個文本框。任何人都可以幫助我實施未來三年?在DIV內容中篩選

例如:

如果我打字pd001它顯示了前兩排,如果我輸入粘貼應該從目前可見的列表不是從整個名單達到和過濾。

請幫助我解決這個問題。

回答

1

如果我沒有錯,那麼你必須要做的是如果我根據pd001搜索2行並將paste放在下一個文本框中,那麼它應該只篩選那些2行而不是整個網格。和所有其他文本框相同的功能。事實上,你需要依賴B/W文本框。

試試這個:

$(".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/

+0

那想我需要和真的謝謝你這麼多修復。偉大的人:) – Harry 2012-08-16 11:29:41

+1

@哈里:很高興它爲你工作。我也會喜歡上一個:-) – codef0rmer 2012-08-16 11:50:53

0

你過濾只有一列,它可以幫助你

$("#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(); 
       } 
      }); 
     }); 
    }); 

});​ 
+1

嗨,謝謝你的努力,但是你的代碼並沒有提供給我o/p我正在尋找的東西...... filiter並沒有像通緝那樣工作。 ANY hw感謝你的努力Ronak :) – Harry 2012-08-16 16:26:17