我需要重用我从外部JSON中提取的股票报价数据

时间:2014-02-17 17:05:39

标签: json

我用这个创建了股票报价......

function quote_search(json) {
  var symbol = document.getElementById("symbol_span");
  var last = document.getElementById("last_span");
  var exchange = document.getElementById("exchange_span");
  var change = document.getElementById("change_span");

  symbol.innerHTML = json.symbol;
  last.innerHTML = json.last;
  exchange.innerHTML = json.exchange;
  change.innerHTML = json.change;
}

它填满了这张桌子......

<table id="stock-data">
  <tr>
    <td id="symbol_span"></td>
    <td id="last_span"></td>
  </tr>
  <tr>
    <td id="exchange_span"></td>
    <td id="change_span"></td>
  </tr>
</table>

我想在另外两个股票报价上重复使用相同的数据。有没有办法可以做到这一点?非常感谢任何帮助。

更新:

这是我的更新代码,感谢Degenerate ...

var stockData;

function quote_search(json) {

  window.stockData = json;

  var symbol = document.getElementById("symbol_span");
  var last = document.getElementById("last_span");
  var exchange = document.getElementById("exchange_span");
  var change = document.getElementById("change_span");

  symbol.innerHTML = json.symbol;
  last.innerHTML = json.last;
  exchange.innerHTML = json.exchange;
  change.innerHTML = json.change;

  symbol3.innerHTML = window.stockData.symbol;
  exchange3.innerHTML = window.stockData.exchange;
  change3.innerHTML = window.stockData.change;
}

0 个答案:

没有答案