开发者

How do you ensure jQuery is available when loaded asynchronously

Google allows you to load jQuery asynchronously like so:

<script sr开发者_C百科c="http://www.google.com/jsapi?key=..." type="text/javascript"></script> 
<script> 
  //<![CDATA[
    google.load('jquery', '1.6');
  //]]>
</script>
<script src="scripta.js" type="text/javascript"></script>
<script src="scriptb.js" type="text/javascript"></script>

In later scripts, how do I ensure jQuery has been loaded? I could use setInterval to check whether jQuery is set, but suppose scriptb.js depends on scripta.js, and both are wrapped in a setInterval to wait for jQuery, and so the interval will "randomly" execute either one first.

How can I approach this problem?

Thanks!


Assign the optional setting callback (documentation):

google.load('jquery', '1.6', {"callback":jqueryLoaded});

function jqueryLoaded(){
alert('loaded');
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜