Вопрос по jquery – jQuery ценовой фильтр

4

Error: User Rate Limit Exceeded

HTML:

<div class="demo">

<p>
    <label for="amount">Price range:</label>
    <input type="text" id="amount" style="border:0; color:#f6931f; font-weight:bold;" />
</p>

<div id="slider-range"></div>
<ul>
        <li> product - £10 </li>
        <li> product - £50 </li>
        <li> product - £100 </li>
        <li> product - £150 </li>
        <li> product - £200 </li>
    </ul>
</div>​

JavaScript:

$(function() {
    var options = 
        {
            range: true,
            min: 0,
            max: 500,
            values: [ 50, 300 ],
            slide: function( event, ui ) {
                $( "#amount" ).val( "$" + ui.values[ 0 ] + " - $" + ui.values[ 1 ] );
            }
        };

        $( "#slider-range" ).slider(
            options
        );
        $( "#amount" ).val( "$" + $( "#slider-range" ).slider( "values", 0 ) +
            " - $" + $( "#slider-range" ).slider( "values", 1 ) );
    });

Error: User Rate Limit ExceededError: User Rate Limit Exceeded

Error: User Rate Limit Exceeded Ireally Rock
Error: User Rate Limit Exceeded Andrew Whitaker

Ваш Ответ

1   ответ
15

Error: User Rate Limit Exceeded

  1. Give your list of products an id attribute and give each product a data-price attribute that is equal to the price of the item:

    <ul id="products">
        <li data-price="10"> product - £10 </li>
        <li data-price="50"> product - £50 </li>
        <li data-price="100"> product - £100 </li>
        <li data-price="150"> product - £150 </li>
        <li data-price="200"> product - £200 </li>
    </ul>
    
  2. Add a function that will show or hide those products when a slide event occurs:

    function showProducts(minPrice, maxPrice) {
        $("#products li").hide().filter(function() {
            var price = parseInt($(this).data("price"), 10);
            return price >= minPrice && price <= maxPrice;
        }).show();
    }
    
  3. Call that function from the slide event handler:

    slide: function(event, ui) {
        var min = ui.values[0],
            max = ui.values[1];
    
        $("#amount").val("$" + min + " - $" + max);
        showProducts(min, max);
    }
    
  4. Also call that function right after the slider is initialized so that the correct products are hidden initially:

    var options = {
       /* snip */
    }, min, max;
    
    $("#slider-range").slider(options);
    
    min = $("#slider-range").slider("values", 0);
    max = $("#slider-range").slider("values", 1);
    
    $("#amount").val("$" + min + " - $" + max);
    
    showProducts(min, max);
    

Error: User Rate Limit Exceeded

function showProducts(minPrice, maxPrice) {
    $("#products li").hide().filter(function() {
        var price = parseInt($(this).data("price"), 10);
        return price >= minPrice && price <= maxPrice;
    }).show();
}

$(function() {
    var options = {
        range: true,
        min: 0,
        max: 500,
        values: [50, 300],
        slide: function(event, ui) {
            var min = ui.values[0],
                max = ui.values[1];

            $("#amount").val("$" + min + " - $" + max);
            showProducts(min, max);
        }
    }, min, max;

    $("#slider-range").slider(options);

    min = $("#slider-range").slider("values", 0);
    max = $("#slider-range").slider("values", 1);

    $("#amount").val("$" + min + " - $" + max);

    showProducts(min, max);
});​

Example: Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded Ireally Rock
Error: User Rate Limit Exceededaccept the answerError: User Rate Limit Exceeded

Похожие вопросы