"TypeError:$(...)为空"这是怎么回事? [英] "TypeError: $(...) is null" What's Going On?

查看:127
本文介绍了"TypeError:$(...)为空"这是怎么回事?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Firebug给出了错误:

Firebug is giving the error:

TypeError: $(...) is null
$('#menu img').hover(

我不知道为什么.看似有问题的脚本是这样的脚本,当光标悬停在图像上时,它将替换图像:

I have no idea why. The seemingly problematic script is this which replaces an image when the cursor hovers over an image:

$(document).ready(function()
{
    var storeNormalPath;
    $('#menu img').hover(
        function()
        {   
            storeNormalPath = $(this).attr('src');
            var imgArray = $(this).attr('src').split('.jpg');
            $(this).attr('src', imgArray[0]+'Hover.jpg');
        }, 
        function() 
        {   
            $(this).attr('src', storeNormalPath);
        }
        ).click (function()
        {
            //empty now
        });
});

推荐答案

使用chrome的控制台浏览页面后,即使$(document)都返回null. jQuery(document)可以正常工作,这表明与jQuery的$运算符存在某些冲突.

After some looking over your page using chrome's console, it looks that even $(document) is returning null. jQuery(document) however, works, which suggests there is something in conflict with jQuery's $ operator.

(:我会将您引向以下问题: $ .document为空)

(Source: I would direct you to this question: $.document is null)

看到页面标题中同时引用了 jquery-1.5.1.min.js jquery.1.4.2.js ,也许这可能是冲突的原因?您是否尝试过仅加载其中之一?

Seeing that you have both jquery-1.5.1.min.js AND jquery.1.4.2.js referenced in your page header, perhaps that could be the reason of the conflict? Have you tried loading only one of them?

让我们知道是否有帮助,对不起,我没有更多帮助. 祝你好运!

Let us know if that helps, sorry I couldn't be more help. Good luck!

这篇关于"TypeError:$(...)为空"这是怎么回事?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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