将查询结果分配给变量并在javascript中使用它

时间:2013-05-04 08:17:19

标签: javascript jquery

 <script type="text/javascript">
$('x').load("https://blockchain.info/q/getreceivedbyaddress/1Pt9TRJKeAW61aR1ELQpUZKdMaYXzkCTrn",function(){
  var formatted_value=$('x').text();//$('**x**') is selector for the class
  var goalGauge = new Gauge();
  goalGauge.draw(formatted_value); 
});
</script>
<canvas id="gauge" width="240" height="240" style="display: block; width: 240px; margin: 0px auto;"></canvas></div>

查询发送一个用于填充仪表的数字。如何将收到的值分配给var formatted_value?

现在有效。代码是:

<div style="width: 100%; float: left;">
 <div id="x"></div>
<canvas id="gauge" width="240" height="240" style="display: block; width: 240px; margin: 0px auto;"></canvas>
</div>
<script type="text/javascript">
$('#x').load("https://blockchain.info/q/getreceivedbyaddress/1Pt9TRJKeAW61aR1ELQpUZKdMaYXzkCTrn", function () {
var formatted_value = $('#x').text(); //$('**x**') is selector for the class
var goalGauge = new Gauge();
goalGauge.draw(formatted_value);
});
</script>

1 个答案:

答案 0 :(得分:1)

加载是异步的,

$('**x**').load("https://blockchain.info/q/getreceivedbyaddress/********",function(){
      var formatted_value=$('**x**').text();//$('**x**') is selector for the class
      var goalGauge = new Gauge();
      goalGauge.draw(formatted_value); 
});