jquery – Google Charts API使用$(document).ready方法显示空白屏幕

前端之家收集整理的这篇文章主要介绍了jquery – Google Charts API使用$(document).ready方法显示空白屏幕前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有几个函数使用Google Charts API实例化各种图表。

当我调用他们没有jQuery的$(document).ready方法,一切工作正常。但是用这种方法,我看着黑屏。

为什么?

  1. <script type="text/javascript" src = "http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.js" charset="utf-8"></script>
  2. <script type="text/javascript" src = "http://www.google.com/jsapi" charset="utf-8"></script>
  3. function drawColumnChart1(){..some code..}
  4. function drawColumnChart2(){..some code..}
  5. function drawGeoChart(){.some code..}
  6.  
  7. //This works fine.
  8. google.load("visualization","1",{packages:["piechart","corechart","geomap"]});
  9. google.setOnLoadCallback(window.drawColumnChart1);
  10. google.setOnLoadCallback(window.drawColumnChart2);
  11. google.setOnLoadCallback(window.drawGeoChart);
  12.  
  13.  
  14.  
  15. //This doesn't work
  16. $(document).ready(function(){
  17. google.load("visualization","geomap"]});
  18. google.setOnLoadCallback(window.drawColumnChart1);
  19. google.setOnLoadCallback(window.drawColumnChart2);
  20. google.setOnLoadCallback(window.drawGeoChart);
  21. });

更新
这里是我在Firebug中得到的错误

  1. uncaught exception: [Exception... "Could not convert JavaScript argument" nsresult: "0x80570009 (NS_ERROR_XPC_BAD_CONVERT_JS)" location: "JS frame :: http://www.google.com/jsapi :: Q :: line 20" data: no]
  2. http://www.google.com/jsapi
  3. Line 22

解决方法

google.setOnLoadCallback with jQuery $(document).ready(),is it OK to mix?

可能是最接近的答案,Ryan Wheale对下面的答案也可能是有帮助的。

Is it ok to use google.setOnLoadCallback multiple times?

猜你在找的jQuery相关文章