jquery和javascript过滤问题

jquery和javascript过滤问题,javascript,jquery,filtering,Javascript,Jquery,Filtering,我的JS代码有两个问题,非常感谢您的帮助 我需要添加一个逻辑,以便当有定价为499美元的产品时,“超过50”选项显示在筛选列表中。在我当前的实现中,这不起作用 <li> <!-- over 50 product is not showing when filtering --> <a href="/product-three">Product Four</a><br> <span id="lowestPri

我的JS代码有两个问题,非常感谢您的帮助

  • 我需要添加一个逻辑,以便当有定价为499美元的产品时,“超过50”选项显示在筛选列表中。在我当前的实现中,这不起作用

    <li>
        <!-- over 50 product is not showing when filtering -->
        <a href="/product-three">Product Four</a><br>
        <span id="lowestPriceRange">400</span>
        <span id="highestPriceRange">400</span>
    </li>
    
    
    // Because I need to handle it here somehow but I'm stuck
    var hidePrices = {};
    hidePrices[0] = true;
    hidePrices[10] = true;
    hidePrices[20] = true;
    hidePrices[30] = true;
    hidePrices[40] = true;
    hidePrices[50] = true;
    
    $('#products').find('span').each(function(i, el){
        var key = parseInt(Math.floor($(this).html() / 10) * 10, 10);
        hidePrices[key] = false;
    });
    
    $('#filterByPrice').find('li').each(function(i, el){
        if (hidePrices[Number($(this).find('a').attr('name'))]) {
            $(this).hide();
        }
    });
    

  • 400 400
  • //因为我需要在这里处理,但我被卡住了 var hidePrices={}; hidePrices[0]=真; hidePrices[10]=真; hidePrices[20]=真; hidePrices[30]=真; hidePrices[40]=真; hidePrices[50]=真; $('#products')。查找('span')。每个(函数(i,el){ var key=parseInt(Math.floor($(this.html()/10)*10,10); hidePrices[键]=假; }); $('filterByPrice')。查找('li')。每个(函数(i,el){ if(hidePrices[Number($(this).find('a').attr('name'))])){ $(this.hide(); } });
  • 它隐藏了一些我想展示的产品。例如,当选择了$40-$50筛选选项时,我想显示定价在$40-$60之间的产品


  • 在这里,我修复了您的问题:

    为了解决第一个问题,我添加了以下内容,因为您的密钥是400:

    if (key > 50) key = 50;
    
    为了解决第二个问题,我更改了以下内容:

    return (minProductPrice >= minSelectedPrice && maxProductPrice <= maxSelectedPrice);
    

    返回(minProductPrice>=minSelectedPrice&&maxProductPrice=minSelectedPrice&&minProductPrice=minSelectedPrice&&maxProductPrice将代码的相关部分粘贴到此处。如果JSFIDLE今晚停机怎么办?你的问题没有任何意义。说得好。现在将代码示例添加到我的帖子中。如果你想添加更多的范围。这是完美的现在…我不能感谢你足够!我仍在学习Javascript和你的帮助非常感谢。
    
    return ((minProductPrice >= minSelectedPrice &&  minProductPrice <= maxSelectedPrice) || (maxProductPrice >= minSelectedPrice &&  maxProductPrice <= maxSelectedPrice));