Google Finance API から株価情報を取得して表示することはできますが、株価を追加して合計金額を表示したいと考えています。次のコードがあるとします。
HTML
<link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.0-rc2/css/bootstrap.css">
<script type="text/javascript" src="//code.jquery.com/jquery-1.9.1.js"></script>
<body>
<div class="container">
<h1>Stock Portfolio</h1>
<h2>Total Portfolio Value:</h2>
<div class="total"></div>
<h3>Stocks</h3>
<div class="stockTick"></div>
<div class="stockTick2"></div>
</div>
jQuery
$(document).ready(function(){
$.getJSON('https://finance.google.com/finance/info?client=ig&q=NYSE:FB&callback=?',function(response){
var stockInfo = response[0];
var stockString =
'<div class="stockWrapper">';
stockString +='Company: <span class="stockSymbol"><b>'+stockInfo.t+'</b></span><br />';
stockString +='Price: <span class="stockPrice">'+stockInfo.l+'</span><br />';
stockString +='Change: <span class="stockChange">'+stockInfo.c+'</span><br />';
stockString +=' Reported at: <span>at</span> <span class="stockTime">'+stockInfo.ltt+'</span><hr>';
stockString +='</div>';
$('.stockTick').prepend(stockString);
});
$.getJSON('https://finance.google.com/finance/info?client=ig&q=NYSE:USMD&callback=?',function(response){
var stockInfo = response[0];
var stockString2 =
'<div class="stockWrapper">';
stockString2 +='Company: <span class="stockSymbol"><b>'+stockInfo.t+'</b></span><br />';
stockString2 +='Price: <span class="stockPrice">'+stockInfo.l+'</span><br />';
stockString2 +='Change: <span class="stockChange">'+stockInfo.c+'</span><br />';
stockString2 +=' Reported at: <span>at</span> <span class="stockTime">'+stockInfo.ltt+'</span>';
stockString2 +='</div>';
$('.stockTick2').prepend(stockString2);
});
});