Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/84.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
展开菜单和可展开/可折叠列表之间的jQuery脚本冲突_Jquery - Fatal编程技术网

展开菜单和可展开/可折叠列表之间的jQuery脚本冲突

展开菜单和可展开/可折叠列表之间的jQuery脚本冲突,jquery,Jquery,我目前正在重新设计一个响应性强的网站。当我必须在页面中链接特定的jQuery文件时,我遇到了一个问题 第一个文件是顶部的移动菜单,基本上显示三行,当你点击它们时,它向下展开显示菜单 第二个脚本是我用于可折叠列表的脚本 出现的问题是,当两者都包含时,菜单始终会展开,而不是仅在单击时展开。可折叠列表的功能正是它应该实现的 在过去,我在同一个页面上使用了两个脚本,没有任何问题,但是那就是使用.asp页面而不是.html,我认为这不重要 以下是菜单的第一个脚本的副本: (function ($, win

我目前正在重新设计一个响应性强的网站。当我必须在页面中链接特定的jQuery文件时,我遇到了一个问题

第一个文件是顶部的移动菜单,基本上显示三行,当你点击它们时,它向下展开显示菜单

第二个脚本是我用于可折叠列表的脚本

出现的问题是,当两者都包含时,菜单始终会展开,而不是仅在单击时展开。可折叠列表的功能正是它应该实现的

在过去,我在同一个页面上使用了两个脚本,没有任何问题,但是那就是使用.asp页面而不是.html,我认为这不重要

以下是菜单的第一个脚本的副本:

(function ($, window, document, undefined)
{
    'use strict';

    $(function ()
    {
        $("#mobileMenu").hide();
        $(".toggleMobile").click(function()
        {
            $(this).toggleClass("active");
            $("#mobileMenu").slideToggle(500);
        });
    });
    $(window).on("resize", function()
    {
        if($(this).width() > 500)
        {
            $("#mobileMenu").hide();
            $(".toggleMobile").removeClass("active");
        }
    });
})(jQuery, window, document);
以及可折叠列表的脚本:

$(function prepareList() {
$('#expList').find('li:has(ul)').unbind('click').click(function(event) {
    if(this == event.target) {
        $(this).toggleClass('expanded');
        $(this).children('ul').toggle('medium');
    }
    return false;
}).addClass('collapsed').removeClass('expanded').children('ul').hide();

//Hack to add links inside the cv
$('#expList a').unbind('click').click(function() {
    window.open($(this).attr('href'),'_self');
    return false;
});
//Create the button functionality
$('#expandList').unbind('click').click(function() {
    $('.collapsed').addClass('expanded');
    $('.collapsed').children().show('medium');
})
$('#collapseList').unbind('click').click(function() {
    $('.collapsed').removeClass('expanded');
    $('.collapsed').children().hide('medium');
})
});



//Functions to execute on loading the document

$(document).ready( function() {
prepareList()
});
我把它弄得有点乱,试图找出问题,但我能找到的是,如果我去掉第二个脚本的第一行

$(function prepareList() 
菜单将恢复正常工作,但折叠列表当然会停止


如果您有任何想法尝试,我将不胜感激

你没有得到一个ReferenceError:当你使用所有你发布的代码时,prepareList没有定义?@MartinErnst非常感谢!我没有考虑过。我在最后删除了这段代码,因为这就是我发现的引用错误所指向的,现在它就像一个符咒。我不知道为什么它在以前的网站上使用相同的代码,但我很高兴你为我指出了解决方案。