我试图在我的滑块中动态设置最大值,最大值是从输入#max获得的,我试图用$(“#max”).val来放这段代码最大变量,但它不工作。动态设置最大值到滑块
编辑: 当用户选择一个类别,我显示所有的产品从该类别,并且与AJAX部分I的值设定为输入#max(最大价)
//When user select one category, I display all the product from this category, and in my ajax part I
$('#category').change(function() {
$.ajax({
url: 'ajax.php',
data: {category: category},
dataType: 'json',
cache: false,
type: "GET",
success: function(data){
if (data.length > 0) {
data.forEach(function (elem) {
$('#max').val(elem.MaxPrice); //set the Maximum price in the hidden input
$('#listing_annonce_int').append('<div id="title">'+ elem.title +'</div><div id="price">'+ elem.price +'</div>');
})
}
}
})
});
/**************************************/
function showProducts(minPrice, maxPrice) {
$("#listing_annonce_int .listing_annonce_view").hide().filter(function() {
var price = parseInt($(this).data("price"), 10);
return price >= minPrice && price <= maxPrice;
}).show();
}
$(function() {
var options = {
range: true,
min: 0,
max: 20000,
values: [0, 5000],
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);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
<select id="category" name="category">
<option value='1'>cat 1</option>
<option value='2'>cat 2</option>
</select>
<input type="text" id="amount"/>
<input type="text" id="max"/>
<div id="slider-range"></div>
谢谢,它不适合我,因为输入不是由用户填写,当输入选择类别更改时,此输入将获得他的值,所以我尝试 $('#category')。change(function(){ $(“#slider-range”).slider(“option”,“max”,parseInt($(#max).val())); }); 但它不工作,有什么想法? – Eagle
我没有看到这样的元素。请提供更多#category的代码。 –
对不起,我添加了代码:) – Eagle