Modify the script part like this:
$('#buying_slider_min').change(function() {
var min = parseInt($(this).val());
var max = parseInt($('#buying_slider_max').val());
if (min > max) {
$(this).val(max);
$(this).slider('refresh');
}
});
$('#buying_slider_max').change(function() {
var min = parseInt($('#buying_slider_min').val());
var max = parseInt($(this).val());
if (min > max) {
$(this).val(min);
$(this).slider('refresh');
}
});
Updated fiddle - http://jsfiddle.net/NkjQr/12/
Edit - Code explanation:
1) The value of the slider taken using val()
method is a string and earlier you were comparing those strings,wherein you should be comparing numbers.Since strings were compared,the code was not working the way it should be.Converted the strings to number and then did the min and max comparison.
2) If slider_min value goes beyond slider_max value,slider_min value should be kept at slider_max value.Similarly if slider_max value goes under slider_min value,slider_max value should be kept at slider_min value.These are handled within the respective if
statements
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…