Google AJAX API、jQuery 和google.load() 与 $(function() {})

发布于 2024-08-03 13:58:22 字数 308 浏览 2 评论 0原文

当我使用 google.load() 加载 jquery 时,我用什么来代替

$(function() {
 ... 
});

is ...

google.setOnLoadCallback(function() {
 ...
});

是一样的东西?如果我使用 google.load() 加载很多内容,这可能会太慢?

那么会

google.load("jquery", "1.3.2", {callback: docLoaded()});

在整个文档加载后运行吗?

when i use google.load() to load jquery, what do i use in place of

$(function() {
 ... 
});

is ...

google.setOnLoadCallback(function() {
 ...
});

the same thing? this may be too slow if i am loading alot with google.load()?

then will

google.load("jquery", "1.3.2", {callback: docLoaded()});

run AFTER the whole document is loaded?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

自演自醉 2024-08-10 13:58:22

看看这里:
Google Ajax Apis Playground

他们的做法就像这 :

google.load("jquery", "1");

function OnLoad(){
  // some Jquery instructions
}

google.setOnLoadCallback(OnLoad);

Take a look here :
Google Ajax Apis Playground

The way they do it is like this :

google.load("jquery", "1");

function OnLoad(){
  // some Jquery instructions
}

google.setOnLoadCallback(OnLoad);
不一样的天空 2024-08-10 13:58:22

我认为你仍然应该安全地使用 $(function) ,因为它会等待 google 加载 jQuery,它毕竟是文档的一部分。还是我这里错了?

无论如何,我总是使用本地版本..只是感觉更安全,你知道(:

编辑:刚刚测试了它,它起作用了,只需使用常规的$(function)

I think you should be safe using $(function) still, since it will wait for google to load jQuery, it is after all a part of the document. Or am I wrong here?

I always use local versions anyway..Just feels safer, you know (:

edit: Just tested it, and it worked, just using the regular $(function)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文