-1

I'm trying to add two values from a JSON feed: http://api.jo.je/virginmoneygiving/jsonp.php?d=59024&callback=?

I need to add 'money_total' and 'money_gift_aid'

How do I do that? Currently I'm just showing data.money_total using the code below...

var $js2 = jQuery.noConflict(); 
$js2(function() {
$js2.getJSON('http://api.jo.je/virginmoneygiving/jsonp.php?d=59024&callback=?', {},  function (data) {   
$js2('#raised').html("Total: <span>£" + data.money_total + "</span>");
var donations = "";
$js2.each(data.donations, function(index, value) {                        
if (index < 1)
{
donations  = donations + "<strong>Latest: " + value.person + ",</strong>" + " £" + value.amount;
}
});            
$js2('#donations').html(donations);
})  
});

Can anyone help please?

Thanks, Matt

4

1 回答 1

0

你可以做这样的事情。

parseFloat(data.money_total) + data.money_gift_aid

使用parseIntasmoney_total从 JSON 响应中作为字符串返回。

完整线路:

$js2('#raised').html("Total: <span>£" + (parseFloat(data.money_total) + data.money_gift_aid) + "</span>");
于 2013-06-10T15:11:03.703 回答