2016-05-14 43 views
0

嗨,我是用這個範圍滑塊: http://rangeslider.js.org/Rangeslider.js加小數點輸出

我想知道如何在輸出DIV加小數點像這樣:1.000,000

+0

99%的問題需要[MCVE(** M ** inimal,** C ** omplete和** V ** erifiable ** E ** xample)](http ://stackoverflow.com/help/mcve)。 請發佈與您的問題相關的JavaScript/jQuery,CSS和HTML。使用任何或所有以下服務創建演示: [jsFiddle.net](https://jsfiddle.net/), [CodePen.io](https://codepen.io/), [Plunker。 (http://plnkr.co/), [JS Bin](https://jsbin.com/) 或片段(位於文本編輯器工具欄或CTRL + M上的第7個圖標)。 – zer00ne

回答

0

對不起,但我實際上有同樣的問題...

該示例從「0」到「100」 - 想知道如何改變它的方式,它從「0」到「100000」並顯示「100.000」而不是「100000」。

此外,知道是否可以添加「€」符號會很好嗎?

非常感謝大家能夠幫助的人!

http://codepen.io/andreruffert/pen/meeOav

HTML

<h1>Vertical orientation support</h1> 
<input type="range" data-orientation="vertical"> 
<output></output> 

的Javascript:

var $element = $('input[type="range"]'); 
var $output = $('output'); 

function updateOutput(el, val) { 
    el.textContent = val; 
} 

$element 
    .rangeslider({ 
    polyfill: false, 
    onInit: function() { 
     updateOutput($output[0], this.value); 
    } 
    }) 
    .on('input', function() { 
    updateOutput($output[0], this.value); 
    }); 

CSS

output { 
    font-size: 2em; 
    padding: .3em; 
} 
0

我想出一個朋友的幫助下解決方案。 在調用函數啓動滑塊的位置進行這些更改。

這是怎樣的代碼看起來原本:

var $element1 = $('#slider_range_1'); 
var $output1 = $('#output_1'); 

$element1 
    .rangeslider({ 
    polyfill: false, 
    onInit: function() { 
    updateOutput($output1[0], this.value.toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, '$1,')); 
    } 
}) 

.on('input', function() { 
    updateOutput($output1[0],parseInt(this.value).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, '$1,')); 
    console.log(this.value); 
}); 

的一段代碼如下格式輸出和小數點和美元符號添加到它

.toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, '$1,') 

的代碼應該是這樣的在你做出改變之後。

var $element1 = $('#slider_range_1'); 
var $output1 = $('#output_1'); 

$element1 
    .rangeslider({ 
    polyfill: false, 
    onInit: function() { 
    updateOutput($output1[0], this.value.toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, '$1,')); 
    } 
}) 

.on('input', function() { 
    updateOutput($output1[0],parseInt(this.value).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, '$1,')); 
    console.log(this.value); 
});