如何在价格滑块值上添加逗号

时间:2015-11-18 11:10:24

标签: jquery

我使用jquery完成了价格范围。但我无法在其价值上添加逗号 请在此处查看图像并输入图像说明。这是我的代码

我需要第二个 enter image description here



<script>
    $(function() {
        $( "#slider-range" ).slider({
            range: true,
            min: 250000,
            max: 2000000,
            values: [ 250000, 2000000 ],
            slide: function( event, ui ) {
                $( "#amount" ).val( "$" + ui.values[ 0 ] + " to $" + ui.values[ 1 ] );
            }
        });
        $( "#amount" ).val( "$" + $( "#slider-range" ).slider( "values", 0 ) +
            " to $" + $( "#slider-range" ).slider( "values", 1 ) );
    });
</script>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

  $( "#amount" ).val( "$" + $( "#slider-range" ).slider( "values", 0 ) +
            " to $" + $( "#slider-range" ).slider( "values", 1 ) );

  $("#amount").val("$" + $("#slider-range").slider("values", 0).toString().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,") +
            " to $" + $("#slider-range").slider("values", 1).toString().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,"));

$("#amount").val("$" + ui.values[ 0 ] + " to $" + ui.values[ 1 ] );

为:

$("#amount").val("$" + ui.values[0].toString().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,") + " to $" + ui.values[1].toString().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,"));