-1

Twitterハンドルのフォロー数を表示するブロックがあります。よく働く。唯一の問題は、11,000人以上のフォロワーがいて、APIがカンマをスローしないことです。JavaScriptを組み込んで数値をフォーマットし、見栄えを良くするにはどうすればよいですか?

これが私が使用しているTwitterコードです:

$(function(){
$.ajax({
   url: 'http://api.twitter.com/1/users/show.json',
   data: {screen_name: 'handle'},
   dataType: 'jsonp',
   success: function(data) {
        $('#followers').html(data.followers_count);
   }
});
});


解決策を手伝ってくれたneikerに感謝します!

function numberWithCommas(x) {
        return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
    }

    $.ajax({
       url: 'http://api.twitter.com/1/users/show.json',
       data: {screen_name: 'handle'},
       dataType: 'jsonp',
       success: function(data) {
            $('#followers').html(numberWithCommas(data.followers_count));
       }
    });
4

1 に答える 1

0
 function numberWithCommas(x) {
        return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
    }

    $.ajax({
       url: 'http://api.twitter.com/1/users/show.json',
       data: {screen_name: 'handle'},
       dataType: 'jsonp',
       success: function(data) {
            $('#followers').html(numberWithCommas(data.followers_count));
       }
    });
于 2012-11-23T17:42:39.897 に答える