0

从昨天开始,我一直在尝试解决这个问题,但我无法理解它。我正在异步加载我的谷歌地图,但以下代码会引发一个错误,这是由于信息框未正确加载。

我的错误是:未定义信息框

我的代码是:

function loadScript(callback) {
   var map = document.createElement('script');
   map.type = 'text/javascript';
   map.src = 'https://maps.googleapis.com/maps/api/js?key=my_key_goes_here&sensor=false&callback=initialize';
   document.body.appendChild(map);            
   map.onload = function() {
      var box = document.createElement('script');
      box.type = 'text/javascript';
      box.src = 'https://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/src/infobox_packed.js';
      document.body.appendChild(box);
      box.onload = callback;
   };
}           
window.onload = loadScript;
4

1 回答 1

0

You specify an argument to your loadScript, 'callback'. Then in your map.src you specify callback=initialize. You call loadScript on window.onload, but you don't specify an argument to it. So box.onload doesn't know any value for callback I'm guessing, as it can't magically guess 'initialize' from the map.src string.

Make sense?

于 2013-04-25T13:52:29.470 回答