为什么我得到一个jQuery没有定义的错误? [英] Why am I getting a jQuery is not defined error?

查看:137
本文介绍了为什么我得到一个jQuery没有定义的错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须使用外部js文件才能加载jquery。我的js文件中的代码如下所示:

  document.write('< script language =javascripttype =text / javascriptsrc =http://code.jquery.com/jquery-1.4.4.min.js>< / script>'); 
$ b $($){
$(document).ready(function(){
alert('it works !!');
});
})(jQuery);

在firefox萤幕控制台中,我看到这个错误:jQuery没有定义,我认为是因为jQuery库是从我的js文件中加载$函数之后的。



你有什么想法可以解决这个问题吗?如果我从firebug控制台运行脚本,一切正常。

解决方案

你是正确的jquery没有被加载的时间叫它。你将不得不编写一个函数来加载jQuery库,然后再调用你的代码。或者,你可以延迟你的代码执行,但这不是100%完全证明。



更新。
链接检查jQuery是否已经加载有用的回调电话。


I have to use an external js file in order to load jquery. The code from my js file is below:

 document.write('<script language="javascript" type="text/javascript" src="http://code.jquery.com/jquery-1.4.4.min.js"></script>');

    (function($) {
        $(document).ready(function() {
            alert('it works!!');
        });
    })(jQuery);

In the firefox firebug console I see this error: "jQuery is not defined" and I think it is because the jQuery library is loaded after the $ function from my js file.

Do you have any idea about how can I fix this? If I run the script from the firebug console everything works fine.

解决方案

You are correct about jquery not being loaded at the time you call it. You'll have to write a function that will load the jQuery library and only later call your code. Alternatively you can delay your code execution, but this is not 100% full proof.

Update. Link to check if jQuery has been loaded useful for a callback call.

这篇关于为什么我得到一个jQuery没有定义的错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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