Hi I am having a "Uncaught ReferenceError: $ is not defined" while using bellow codes
嗨我在使用波纹管代码时遇到“未捕获的ReferenceError:$未定义”
I am currently getting the following error in my log. I have been looking at the samples in the framework and I just can't seem to find where the error is. It's been over a decade since I have done any HTML or js and what I did back then was very basic stuff. Any help would be appreciated
我目前在日志中收到以下错误。我一直在看框架中的示例,我似乎无法找到错误的位置。自从我做了任何HTML或js以来已经过去十多年了,我当时所做的事情是非常基本的东西。任何帮助,将不胜感激
<script type="text/javascript">
var sQuery = '<?php echo $sQuery; ?>';
$(document).ready(function(){
if($('input[name=sPattern]').val() == sQuery) {
$('input[name=sPattern]').css('color', 'gray');
}
$('input[name=sPattern]').click(function(){
if($('input[name=sPattern]').val() == sQuery) {
$('input[name=sPattern]').val('');
$('input[name=sPattern]').css('color', '');
}
});
$('input[name=sPattern]').blur(function(){
if($('input[name=sPattern]').val() == '') {
$('input[name=sPattern]').val(sQuery);
$('input[name=sPattern]').css('color', 'gray');
}
});
$('input[name=sPattern]').keypress(function(){
$('input[name=sPattern]').css('background','');
})
});
function doSearch() {
if($('input[name=sPattern]').val() == sQuery){
return false;
}
if($('input[name=sPattern]').val().length < 3) {
$('input[name=sPattern]').css('background', '#FFC6C6');
return false;
}
return true;
}
</script>
7 个解决方案
#1
10
It seems you don't import jquery. Those $ functions come with this non standard (but very useful) library.
看来你没有导入jquery。这些$函数附带了这个非标准(但非常有用)的库。
Read the tutorial there : http://docs.jquery.com/Tutorials:Getting_Started_with_jQuery It starts with how to import the library.
在那里阅读教程:http://docs.jquery.com/Tutorials:Getting_Started_with_jQuery它从如何导入库开始。
#2
8
No need to use jQuery.noConflict
and all
无需使用jQuery.noConflict等等
Try this instead:
试试这个:
// Replace line no. 87 (guessing from your chrome console) to the following
jQuery(document).ready(function($){
// All your code using $
});
If you still get error at line 87, like Uncaught reference error: jQuery is not defined
, then you need to include jQuery file before using it, for which you can check the above answers
如果你仍然在第87行得到错误,比如Uncaught引用错误:jQuery没有定义,那么你需要在使用它之前包含jQuery文件,你可以检查上面的答案
#3
7
Put this code in the <head></head>
tags:
将此代码放在 标记中:
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.0.min.js"></script>
#4
3
If you are sure jQuery is included try replacing $ with jQuery and try again.
如果您确定包含jQuery,请尝试使用jQuery替换$并再试一次。
Something like
就像是
jQuery(document).ready(function(){..
Still if you are getting error, you haven't included jQuery.
如果你收到错误,你仍然没有包含jQuery。
#5
2
I know this is an old question, and most people have replied with good answers. But for reference and hopefully saving somebody else's time. Check if your function:
我知道这是一个老问题,大多数人都回答了很好的答案。但需要参考,希望能节省别人的时间。检查你的功能是否:
$(document).ready(function(){}
is being called after you have loaded the JQuery library
在加载JQuery库之后调用
#6
1
many other people answered your question above. This problen arises when your script don't find the jQuery script and if you are using other framework or cms then maybe there is a conflict between jQuery and other libraries. In my case i used as following- `
很多其他人在上面回答了你的问题。当您的脚本找不到jQuery脚本并且您正在使用其他框架或cms时,可能会出现这个问题,那么jQuery和其他库之间可能存在冲突。在我的情况下,我使用如下 - `
<script src="js_directory/jquery.1.7.min.js"></script>
<script>
jQuery.noConflict();
jQuery(document).ready(
function($){
//your other code here
});</script>
`
`
here might be some syntax error. Please forgive me because i'm writing from my cell phone. Thanks
这可能是一些语法错误。请原谅我,因为我是用手机写的。谢谢
#7
0
Remember that you must first load jquery script and then the script js
请记住,您必须首先加载jquery脚本,然后加载脚本js
<script type="text/javascript" src="http://code.jquery.com/jquery-2.2.4.min.js"></script>
<script type="text/javascript" src="example.js"></script>
Html is read sequentially!
Html按顺序读取!
#1
10
It seems you don't import jquery. Those $ functions come with this non standard (but very useful) library.
看来你没有导入jquery。这些$函数附带了这个非标准(但非常有用)的库。
Read the tutorial there : http://docs.jquery.com/Tutorials:Getting_Started_with_jQuery It starts with how to import the library.
在那里阅读教程:http://docs.jquery.com/Tutorials:Getting_Started_with_jQuery它从如何导入库开始。
#2
8
No need to use jQuery.noConflict
and all
无需使用jQuery.noConflict等等
Try this instead:
试试这个:
// Replace line no. 87 (guessing from your chrome console) to the following
jQuery(document).ready(function($){
// All your code using $
});
If you still get error at line 87, like Uncaught reference error: jQuery is not defined
, then you need to include jQuery file before using it, for which you can check the above answers
如果你仍然在第87行得到错误,比如Uncaught引用错误:jQuery没有定义,那么你需要在使用它之前包含jQuery文件,你可以检查上面的答案
#3
7
Put this code in the <head></head>
tags:
将此代码放在 标记中:
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.0.min.js"></script>
#4
3
If you are sure jQuery is included try replacing $ with jQuery and try again.
如果您确定包含jQuery,请尝试使用jQuery替换$并再试一次。
Something like
就像是
jQuery(document).ready(function(){..
Still if you are getting error, you haven't included jQuery.
如果你收到错误,你仍然没有包含jQuery。
#5
2
I know this is an old question, and most people have replied with good answers. But for reference and hopefully saving somebody else's time. Check if your function:
我知道这是一个老问题,大多数人都回答了很好的答案。但需要参考,希望能节省别人的时间。检查你的功能是否:
$(document).ready(function(){}
is being called after you have loaded the JQuery library
在加载JQuery库之后调用
#6
1
many other people answered your question above. This problen arises when your script don't find the jQuery script and if you are using other framework or cms then maybe there is a conflict between jQuery and other libraries. In my case i used as following- `
很多其他人在上面回答了你的问题。当您的脚本找不到jQuery脚本并且您正在使用其他框架或cms时,可能会出现这个问题,那么jQuery和其他库之间可能存在冲突。在我的情况下,我使用如下 - `
<script src="js_directory/jquery.1.7.min.js"></script>
<script>
jQuery.noConflict();
jQuery(document).ready(
function($){
//your other code here
});</script>
`
`
here might be some syntax error. Please forgive me because i'm writing from my cell phone. Thanks
这可能是一些语法错误。请原谅我,因为我是用手机写的。谢谢
#7
0
Remember that you must first load jquery script and then the script js
请记住,您必须首先加载jquery脚本,然后加载脚本js
<script type="text/javascript" src="http://code.jquery.com/jquery-2.2.4.min.js"></script>
<script type="text/javascript" src="example.js"></script>
Html is read sequentially!
Html按顺序读取!