使用带滑块的jquery中的逗号将数字格式化为货币

jdolor 发布于 2019-03-09 javascript 最后更新 2019-03-09 14:37 0 浏览

我试图让输出格式为1,023,456.50也为ui.values [0] 但它显示NaN。 有任何想法吗? http://jqueryui.com/slider/#range

$(function() {
        $( "#slider-range" ).slider({
              animate: true,
            range: true,
            min: 0,
            max: 10000000,
            step: 10000,
            values: [ 2000, 8888888 ],
            slide: function( event, ui ) {
                $( "#price-range" ).val( + ui.values[ 0 ].toString().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,") + " - " + ui.values[ 1 ].toString().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,") );
}
        });
        $( "#price-range" ).val( + $( "#slider-range" ).slider( "values", 0 ).toString().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,") +
            " - " + $( "#slider-range" ).slider( "values", 1 ).toString().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,") );
    });
有关原始代码,请参阅:enter link description here
已邀请:

pullam

赞同来自:

您的代码工作正常,但语法错误除外。

$( "#price-range" ).val( +
注意+号。您在输出的文本中也缺少一些$。 具有已修复错误的示例:http://jsfiddle.net/Dq9cP/