我有一个 API 调用,它返回venue_capacity一个足球队的数字,没有千位分隔符。我想将其打印为字符串和千位分隔符。
我的想法是在我从 API 获得数据后运行该函数以相应地操作变量venue_capacity。
这是我当前的尝试返回没有分隔符的数字:
$.ajax({
method: "GET",
async: "True",
dataType: "json",
url: "https://cors-anywhere.herokuapp.com/https://www.api-football.com/demo/api/v2/teams/team/" + team_id,
success: function(response) {
var team_info = response;
console.log(team_info);
team = team_info.api.teams[0].name;
founded = team_info.api.teams[0].founded;
venue_capacity = team_info.api.teams[0].venue_capacity;
function numberWithCommas(venue_capacity) {
return venue_capacity.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ".");
}
$("#selectedClub").html(team);
$("#founded").html(founded);
$("#venue_capacity").html(venue_capacity);
}
哆啦的时光机
DIEA
相关分类