2013-05-04 19 views
1
<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> 

分配查询结果变量和在javascript

的查询中使用它发送其被用于填充计的数目。如何将收到的值分配给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

负载是异步的话,

$('**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); 
}); 
+0

这并不工作。 – user2349327 2013-05-04 08:30:25

+0

我已经改变了上面的代码与全Sript请检查并告诉其正确 – user2349327 2013-05-04 08:31:00

+0

x是什么?它在html中无处可用。 – specialscope 2013-05-04 08:37:58