这个幻灯片范围,当拖动到右边时,我想显示文本,例如:无限制,我该怎么做?

时间:2014-08-28 12:58:32

标签: javascript php jquery

这个幻灯片范围,当拖动到右边时,我想显示文字,例如:unlimited,我该怎么做?

当向右拖动时,普通代码会显示$0 - $500,但我想显示$0 - unlimited

我该怎么做?

http://jsfiddle.net/5Kvk5/1/

$(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 ) );
});

1 个答案:

答案 0 :(得分:0)

您可以通过检查当前最大幻灯片值(ui.values[ 1 ])是否与maxPriceInRupees值相同来执行此操作:

http://jsfiddle.net/5Kvk5/9/

$(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 ))));
});