Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 未捕获类型错误:未定义不是菜单中的函数_Javascript_Jquery - Fatal编程技术网

Javascript 未捕获类型错误:未定义不是菜单中的函数

Javascript 未捕获类型错误:未定义不是菜单中的函数,javascript,jquery,Javascript,Jquery,我发现了一个我的站点的菜单示例,其中包含以下javascript jQuery.fn.initMenu = function() { return this.each(function(){ var theMenu = $(this).get(0); $('.acitem', this).hide(); $('li.expand > .acitem', this).show();

我发现了一个我的站点的菜单示例,其中包含以下javascript

    jQuery.fn.initMenu = function() {  
        return this.each(function(){
            var theMenu = $(this).get(0);
            $('.acitem', this).hide();
            $('li.expand > .acitem', this).show();
            $('li.expand > .acitem', this).prev().addClass('active');
            $('li a', this).click(
                function(e) {
                    e.stopImmediatePropagation();
                    var theElement = $(this).next();
                    var parent = this.parentNode.parentNode;
                    if($(parent).hasClass('noaccordion')) {
                        if(theElement[0] === undefined) {
                           window.location.href = this.href;
                        }
                        $(theElement).slideToggle('normal', function() {
                            if ($(this).is(':visible')) {
                                $(this).prev().addClass('active');
                            }
                            else {
                                $(this).prev().removeClass('active');
                            }    
                        });
                        return false;
                    }
                    else {
                        if(theElement.hasClass('acitem') && theElement.is(':visible')) {
                            if($(parent).hasClass('collapsible')) {
                                $('.acitem:visible', parent).first().slideUp('normal', 
                                function() {
                                    $(this).prev().removeClass('active');
                                }
                            );
                            return false;  
                        }
                        return false;
                    }
                    if(theElement.hasClass('acitem') && !theElement.is(':visible')) {         
                        $('.acitem:visible', parent).first().slideUp('normal', function() {
                            $(this).prev().removeClass('active');
                        });
                        theElement.slideDown('normal', function() {
                            $(this).prev().addClass('active');
                        });
                        return false;
                    }
                }
            }
        );
    });
    };

$(document).ready(function() {$('.menu').initMenu();});
但我总是得到这个错误uncaughttypeerror:undefined不是最后一行的函数

$(document).ready(function() {$('.menu').initMenu();});
请帮帮我,我不知道该怎么办

下面是我如何连接jquery的

<script src="jquery-1.4.2.min.js" type="text/javascript"></script>
<script src="menu.js" type="text/javascript"></script>

您是否包括jQuery?你能把你的HTML放在这里吗?试着使用最新的jquery。我更新了我的问题,我使用jquery 1.4.2JSFIDLE会有所帮助。你使用的是一个有缺陷的4年版jquery,将近5年。是时候咬紧牙关升级了。