我正在尝试将输出格式化为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
答案 0 :(得分:3)
您的代码工作正常,但语法错误除外。
$( "#price-range" ).val( +
注意 + 符号。您输出的文本中也缺少一些 $ 。
带有修正错误的示例:http://jsfiddle.net/Dq9cP/