Google Library API - google.load 不从事件加载? [英] Google Library API - google.load does not load from event?

查看:55
本文介绍了Google Library API - google.load 不从事件加载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我从函数加载库时,它不会加载甚至使页面崩溃!
这是怎么回事??

When I load a library from a function it doesn't load and even crashes the page!
What's up with that??

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()"/>

推荐答案

好吧,看来我们不能动态加载 jQuery:http://code.google.com/apis/loader/#Dynamic

Okay, it seems that we can not load jQuery dynamically: http://code.google.com/apis/loader/#Dynamic

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

The standard google.load functionality loads the API(s) when your page loads

Google Loader 支持、动态加载并带有回调的唯一库是:

The only Libraries supported by Google Loader, loaded dynamically and with callbacks are:

  • Google 地图 API
  • Google 搜索 API
  • Google Feeds API
  • Google 语言 API
  • Google 可视化 API

无赖!

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

I am going for a lazy-load polling plugin: http://wonko.com/post/lazyload-200-released

这篇关于Google Library API - google.load 不从事件加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆