我有一个超级简单的功能,我只想用它来添加多个数字,并将该数字显示为我的页面上的文本。我唯一缺少的功能是逗号分隔格式。我确信这很容易,但我似乎仍无法让它发挥作用。以下是我的代码。
function winnersTotal() {
var jackpotTotal = 1510258 /*Jan & Feb Totals*/;
jackpotTotal.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
document.getElementById("jackpotTotal").innerHTML = "$" + jackpotTotal;
}
答案 0 :(得分:0)
function winnersTotal() {
var jackpotTotal = 1510258 /*Jan & Feb Totals*/;
var withCommas = jackpotTotal.toLocaleString();
document.getElementById("jackpotTotal").innerHTML = "$" + withCommas;
}

<div id="jackpotTotal"></div>
<button onclick="winnersTotal()">Click Me</button>
&#13;