這裏集成支持cookie(它不是那麼好)的dificulties
IM對於JS
$(window).load(function(){
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);
});
});
和HTML代碼
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
<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 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>
</div
這裏是鏈接到我的jsfindle Price slider
它使用jQuery的1.72
我的問題是如何把cookie支持它,所以當遊客選擇一些可以節省他的選擇,當他刷新頁面或者回來的頁面仍然將包括他的選定的值。
試過,但它不保存這兩個值,例如,如果我在159選擇前選擇和結束一個250,然後刷新它顯示了在250至300 。解決這個問題以保存兩個值是否可行?開始和結束? – user1791743
別人來幫助解決這個問題? – user1791743
對此深感抱歉。我只爲'min'值添加了Cookie。現在我也加了'max'的值。上面更新了我的代碼。 –