您好,我在使用以下代码时遇到“未捕获的引用错误:$未定义”
目前我的日志中出现以下错误。我一直在查看框架中的示例,但似乎找不到错误在哪里。我已经有十多年没有做过任何 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>
看来你没有导入jquery http://jquery.com/。这些 $ 函数附带这个非标准(但非常有用)库。
阅读那里的教程:http://docs.jquery.com/Tutorials:Getting_Started_with_jQuery http://docs.jquery.com/Tutorials:Getting_Started_with_jQuery首先从如何导入库开始。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)