我需要将货币输出添加到jQuery函数中。因此像1577334.668这样的数字将打印为1,577,335美元。我认为我应该在控制器中执行此操作,但我的老板今天告诉我,我应该在jQuery视图中执行此任务,我只是不知道该怎么做。我已经在下面包含了jQuery代码,并在我需要以货币打印金额的变量旁边添加了注释。该变量称为SC[i]
。任何建议或意见将不胜感激!谢谢你的帮助!
//Spend Category function for monthly
pa_click = function (pa_label) {
PA_ID = pa_label.getAttribute('pa_id');
var pa_details = document.getElementById('pa-details-' + PA_ID);
jQuery.getJSON('@Url.Action("getAjaxSCs")', { PA: pa_label.title }, function (SCS) {
pa_details.innerHTML = "";
jQuery.each(SCS, function (index, SC) {
months_html = '';
for (var i = 0; i < 12; i++) {
months_html +=
'<div id="SC-' + index + '-' + months[i] + '" class="month-wrapper tree border-white">' +
SC[i] + // This is the variable I need to replace with code to add currency to the amount
'</div>';
}
pa_details.innerHTML +=
'<div id ="Spend-Category-' + index + '" class="sc-wrapper tree border">' +
'<div id ="sc-title-' + index + '" class="sc-title">' +
'<div class = "sc-label" title = "' + index + '" SC_id="' + index + '" onclick = "sc_click(this)">' + index + '</div>' +
months_html +
'</div>' +
'<div id="sc-details-' + index + '" class = "pa-details" style = "display:none">' + index + '</div>' +
'</div>';
})
});
jQuery('#pa-details-' + PA_ID).show('slide', { direction: 'up' }, 'fast');
};
答案 0 :(得分:1)
这个jQuery插件可以帮助你:Format Currency
在此行中添加一个类(例如货币)
months_html +='<div id="SC-' + index + '-' + months[i] + '" class="month-wrapper tree border-white currency">' +
SC[i] + // This is the variable I need to replace with code to add currency to the amount
'</div>';
然后$(".currency").formatCurrency();
就可以了。
该页面还有一些可以帮助您入门的演示
答案 1 :(得分:0)