Google Library API - google.load无法从事件中加载?

时间:2010-11-07 11:36:13

标签: api loader

当我从函数加载库时,它不会加载甚至崩溃页面!
怎么了?

HTML头:

<script type="text/javascript" src="https://www.google.com/jsapi?key=INSERT-YOUR-KEY"></script>
<script type="text/javascript">
    // --- LOADING LIKE THIS WORKS FINE ---
    // jQuery is completely loaded
    function jqueryLoaded() {
        $("body").css("background-color","orange");
    }
    google.load("jquery", "1.4.3");
    google.setOnLoadCallback(jqueryLoaded);     

    // --- LOADING FROM AN EVENT DOES NOT WORK?? ---
    // jQuery UI is completely loaded
    function jqueryUILoaded() {
        $("body").css("background-color","green");
    }   
    function loadJqueryUI() {
        alert("load jQuery UI now..");
        google.load("jqueryui", "1.8.6");
        google.setOnLoadCallback(jqueryUILoaded);
    }

    // with a setTimeout it doesn't work either.. 
    // setTimeout("loadJqueryUI()", 2000);
</script>  

HTML正文:

<input type="button" value="load jQuery UI" onclick="loadJqueryUI()"/>

2 个答案:

答案 0 :(得分:1)

好的,似乎我们无法动态加载jQuery: http://code.google.com/apis/loader/#Dynamic

  

标准的google.load功能会在您的网页加载时加载API

Google Loader支持的唯一库,动态回调

  • Google Maps API
  • Google Search API
  • Google Feeds API
  • Google语言API
  • Google Visualization API

无赖!

我要使用延迟加载轮询插件: http://wonko.com/post/lazyload-200-released

答案 1 :(得分:0)

您是否考虑过将INSERT-YOUR-KEY替换为您的密钥?