0

我查看了 tolocalestring() 并且它不起作用。

我试图让它:

  • 1,000,000
  • 10,000,000
  • 等等...

这是我的代码:

$(document).ready(function() {
  var number = parseInt($('#test').text(), 10) || 309320350
  number.toLocaleString();

  // Called the function in each second
  var interval = setInterval(function() {
    $('#test').text(number++); // Update the value in paragraph
  }, 1000); // Run for each second
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p id="test"></p>

4

1 回答 1

1

toLocaleString返回一个字符串并number保持不变。它不会“告诉”数字稍后如何格式化(数字不记得),它会格式化它。.text(…)执行输出时需要调用它。

$(document).ready(function() {
  var number = parseInt($('#test').text(), 10) || 309320350

  // Called the function in each second
  var interval = setInterval(function() {
    $('#test').text(number.toLocaleString()); // Update the value in paragraph
    number++;
  }, 1000); // Run for each second
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p id="test"></p>

于 2018-08-02T19:00:13.707 回答