这个幻灯片范围,当拖动到右边时,我想显示文字,例如:unlimited
,我该怎么做?
当向右拖动时,普通代码会显示$0 - $500
,但我想显示$0 - unlimited
我该怎么做?
$(function() {
var minPriceInRupees = 0;
var maxPriceInRupees = 500;
var currentMinValue = 33;
var currentMaxValue = 333;
$( "#slider-range" ).slider({
range: true,
min: minPriceInRupees,
max: maxPriceInRupees,
values: [ currentMinValue, currentMaxValue ],
slide: function( event, ui ) {
$( "#amount" ).val( "$" + ui.values[ 0 ] + " - $" + ui.values[ 1 ] );
currentMinValue = ui.values[ 0 ];
currentMaxValue = ui.values[ 1 ];
}
});
$( "#amount" ).val( "$" + $( "#slider-range" ).slider( "values", 0 ) +
" - $" + $( "#slider-range" ).slider( "values", 1 ) );
});
答案 0 :(得分:0)
您可以通过检查当前最大幻灯片值(ui.values[ 1 ]
)是否与maxPriceInRupees
值相同来执行此操作:
$(function() {
var minPriceInRupees = 0;
var maxPriceInRupees = 500;
var currentMinValue = 33;
var currentMaxValue = 333;
$( "#slider-range" )
.slider({
range: true,
min: minPriceInRupees,
max: maxPriceInRupees,
values: [ currentMinValue, currentMaxValue ],
slide: function( event, ui ) {
$( "#amount" )
.val( "$" + ui.values[ 0 ] + " - " + (ui.values[ 1 ] == maxPriceInRupees ? 'Unlimited' : ('$'+ui.values[ 1 ])) );
currentMinValue = ui.values[ 0 ];
currentMaxValue = ui.values[ 1 ];
}
});
$( "#amount" ).val( "$" + $( "#slider-range" ).slider( "values", 0 ) + " - " + ($( "#slider-range" ).slider( "values", 1 ) == maxPriceInRupees ? 'Unlimited' : ('$' + $( "#slider-range" ).slider( "values", 1 ))));
});