English 中文(简体)
jquery 搜索结果过滤
原标题:jquery search results filtering

正在用 php/ sphinx/ jquery 构建搜索引擎, 我大多数搜索引擎都在工作, 除了过滤搜索结果之外。 搜索结果没有提交过滤器, 所有结果都会显示, 然后在单击复选框时尝试使用 jquery 隐藏不匹配的结果 。

http://jsfidle.net/LEZAh/"rel="nofollow" >http://jsfidle.net/LEZAh/

what works: checking a box and have the corresponding element show, and when another box is checked add it to the allowed boxes to show.

what doesn t work: when you have more than one checkbox checked and you uncheck one of them, the corresponding element does not show.

对错误的解释表示歉意......但填充物会为自己表示感谢!

最佳回答

正如上述优秀职位(mrtsherman,ahren)之外,你其他发言的最后一句话就是造成问题。

    //$(".ni-search"+checks).show(); //this was the offending line

    $("#cat_"+$(this).attr( id )).hide(); //instead of showing everything just hide what was clicked

我在你的小提琴里也成功运行过这个

问题回答

我简化了你的点击功能

$(document).ready( function () {
   $( .search-option input ).click(function(){
      var inputs = $(".search-option input");
      var products = $(".ni-search");

      products.each(function(i){
         if(inputs.eq(i).is(":checked")){
            $(this).show();
         }else{
            $(this).hide();
         }
      });
      if(products.length == inputs.not(":checked").length){
          products.show();  
      }
   });
});​

这假设你的检查结果都会在同一包装纸上, 你的检查框也会在同一包装纸上。

""http://jsfiddle.net/LEZAh/2/" rel="nofollow">链接到更新的jsFiddle

这是您脚本的另一个简化版本。

http://jsfiddle.net/LEZAh/4/" rel="nown" >http://jsfiddle.net/LEZAh/4/

$( input ).change(function() {
    //all checkboxes are unchecked, so show all
    if ($( input:checked ).length == 0) {
        $( .ni-search ).show();
    }
    else {
        //otherwise only show checked
        $( .ni-search ).hide();
        $( input:checked ).each(function(index) {
            $( .ni-search ).eq(index).show();
        });
    }
});​




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签