如何当异步加载的jQuery已完成加载检测? [英] How to detect when asynchronously loaded jquery has finished loading?

查看:316
本文介绍了如何当异步加载的jQuery已完成加载检测?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要jQuery的异步加载一个页面上,然后加载它依赖于一个jQuery的脚本其他(加载时,它执行的jquery code)。但我怎么能检测是否jQuery的已完成lodading。是否有此jQuery中当库加载完成其触发一个事件?

I want to load jquery asynchronously on a page and then load an other script which depends on jquery (it executes jquery code when loaded). But how can I detect if jquery has finished lodading. Is there an event for this in jquery which fires when the library finished loading?

在理论上我可以加载的jQuery是这样的:

In theory I could load jquery like this:

<script async src="jquery.js" onload="jqueryloaded()"></script>

但我想code的工作对旧的浏览器也可能不支持异步和onload事件属性。 (在这种情况下,jQuery是同步加载)。这就是为什么我在寻找时,它的加载它的jQuery发出的事件。有一?

but I want the code to work on older browsers too which may not support the async and onload attributes. (In this case jquery is loaded synchronously.) That's why I'm looking for an event which jquery emits when it's loaded. Is there one?

推荐答案

您可以试试这个:

var script = document.createElement('script');
script.src = 'jquery.js';
script.onload = jqueryloaded; // thx @Cookie_Monster
document.body.appendChild(script);

这篇关于如何当异步加载的jQuery已完成加载检测?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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