Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/383.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 在jquery中打开活动/当前子菜单_Javascript_Jquery_Html_Css - Fatal编程技术网

Javascript 在jquery中打开活动/当前子菜单

Javascript 在jquery中打开活动/当前子菜单,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我在页面上使用了这个jsfiddle()中的菜单 $("#vertical-menu h3").click(function () { //slide up all the link lists $("#vertical-menu ul ul").slideUp(); $('.plus',this).html('+'); //slide down the link list below the h3 clicked - only if its closed if (!$(this).next()

我在页面上使用了这个jsfiddle()中的菜单

$("#vertical-menu h3").click(function () {
//slide up all the link lists
$("#vertical-menu ul ul").slideUp();
$('.plus',this).html('+');
//slide down the link list below the h3 clicked - only if its closed
if (!$(this).next().is(":visible")) {
    $(this).next().slideDown();
    //$(this).remove("span").append('<span class="minus">-</span>');
    $('.plus').html('+');
    $('.plus',this).html('-');
}
$(“#垂直菜单h3”)。单击(功能(){
//向上滑动所有链接列表
$(“#垂直菜单ul”).slideUp();
$('.plus',this.html('+');
//向下滑动h3下的链接列表-仅当其已关闭时
如果(!$(this).next()是(“:可见”)){
$(this.next().slideDown();
//$(this.remove(“span”).append('-');
$('.plus').html('+');
$('.plus',this.html('-');
}
每当我进入一个新的子页面(例如任务>今天的任务),它都会展开菜单的“仪表板”部分,因为它被设置为活动。但我希望它是展开的“任务”部分,因为“今天的任务”是任务的子项

我如何改变这个

我希望它将父li的(任务)类更改为活动类,并从另一个父li(仪表板)中删除该类,等等。 因此,每当我在子网站上时,菜单将扩展菜单的这一部分


我尝试了各种URL比较,将类添加到父类中,但我似乎无法使其工作。

在此粘贴所有js代码。您只粘贴了单击手柄,这是因为我从未找到有效的解决方案。我尝试了类似的方法:
$(function(){var pgurl=window.location.href.substr(window.location.href.lastIndexOf(“/”+1);$(“#垂直菜单ul li a”)。每个(函数(){if($(this.attr)(“href”)==pgurl | |$(this.attr(“href”)==”)(this.addClass(“active”);}或这个:
$(文档)。准备好(函数(){($('#垂直菜单ul ul ul ul')。查找('li')。单击(函数(){//删除以前选择的菜单状态$('#垂直菜单').find('li.active').removeClass('active');//添加此父菜单的状态$(this.parents('li').addClass('active');})
在此粘贴所有js代码。您只粘贴了点击手柄,这是因为我从未找到有效的解决方案。我尝试了类似的解决方案:
$(function(){var pgurl=window.location.href.substr(window.location.href.lastIndexOf(“/”);$(“#垂直菜单ul li a”)。每个(function(){if($(此).attr(“href”)==pgurl | |$(this).attr(“href”)==''$(this.addClass(“active”);})
或this:
$(document).ready(function(){$('.#垂直菜单ul ul ul')。find('li')。单击(function(){//删除以前选择的菜单状态$('.#垂直菜单')。find('li.active')。removeClass('active');//添加此父菜单的状态$(this).parents('li').addClass('active');});});