日期:2014-05-16  浏览次数:20356 次

js回调函数的简单问题
一个简单的html文件,可为什么得不到cc的内容?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
 <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
  <title></title>
  <script type="text/javascript">  
var cc;
var eqfeed_callback = function(data){
alert('数据长度:' + data.features.length + '条');
var count=data.features.length;
  alert('震级:'+ data.features[0].geometry.coordinates[0]);
cc=data;
  }; 
alert(cc);
</script>
<script src="http://earthquake.usgs.gov/earthquakes/feed/geojsonp/significant/week?callback= eqfeed_callback"> </script> 
</head>
<body >
<div id="con"></div>
</body>
</html>

------解决方案--------------------
window.onload = function(){alert(cc)}
------解决方案--------------------
探讨

window.onload = function(){alert(cc)}

------解决方案--------------------
探讨

window.onload = function(){alert(cc)}

------解决方案--------------------

window.test = cc; // 将cc的值赋值给全局test