$(document).ready(function(){Uncaught ReferenceError:$未定义 [英] $(document).ready(function(){ Uncaught ReferenceError: $ is not defined
问题描述
您好我在使用以下代码时遇到未捕获的ReferenceError:$未定义
Hi I am having a "Uncaught ReferenceError: $ is not defined" while using bellow codes
我目前在日志中收到以下错误。我一直在看框架中的示例,我似乎无法找到错误的位置。自从我做了任何HTML或js以来已经过去了十多年,我当时所做的就是非常基本的东西。任何帮助将不胜感激
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
<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>
推荐答案
它好像你没有导入 jquery 。这些$函数附带了这个非标准(但非常有用)的库。
It seems you don't import jquery. Those $ functions come with this non standard (but very useful) library.
在那里阅读教程: http://docs.jquery.com/Tutorials:Getting_Started_with_jQuery
首先介绍如何导入库。
Read the tutorial there : http://docs.jquery.com/Tutorials:Getting_Started_with_jQuery It starts with how to import the library.
这篇关于$(document).ready(function(){Uncaught ReferenceError:$未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!