簡體   English   中英

JavaScript在此計數器中用逗號將小數點替換為小數

[英]JavaScript replace dot with comma as decimal in this counter

我從這里以前的帖子中整理了這個計數器。 我想將小數點更改為逗號,但是我嘗試了此操作,腳本停止了工作。 此外,如何在一行上獲得歐元符號和數字? 我沒有在任何地方“休息”,為什么數字總是在不同的行上?

HTML:
&euro;<div class="counter">92.1</div> is the amount to pay

JavaScript:
function startCounter(){
    $('.counter').each(function (index) {
        var size = $(this).text().split(".")[1] ? $(this).text().split(".")[1].length : 0;
        $(this).prop('Counter',0).animate({
            Counter: $(this).text()
        }, {
            duration: 2000,
            easing: 'swing',
            step: function (now) {
                $(this).text(parseFloat(now).toFixed(size));
            }
        });
    });
}   

startCounter();

此處的JSFiddle: https ://jsfiddle.net/fv7bctba/1/

我嘗試了replace(/,/g, '.')函數。 但是我必須說,我不確定如何使用它。

我也嘗試從中更改split函數。 到,但隨后會給我一個NaN。

<div>是塊級元素,這意味着它們通常在其前后使用換行符進行渲染。 您可以將<div>設置為inline樣式或inline-block樣式,也可以使用已經inline的元素,例如<span>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM