Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/74.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_Html_Css - Fatal编程技术网

Javascript 单击子菜单时,导航链接不会突出显示当前菜单

Javascript 单击子菜单时,导航链接不会突出显示当前菜单,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我已经编写了jquery代码,用于在单击每个子菜单时突出显示菜单。现在发生了什么 我在三个子菜单中有一个相同的链接,所以当我单击其中一个时,它会高亮显示最后一个菜单 这是我的密码:- var str = location.href.toLowerCase(); $("#menu li a").each(function () { if (str.indexOf($(this).attr("href").toLowerCase()) > -1) {

我已经编写了jquery代码,用于在单击每个子菜单时突出显示菜单。现在发生了什么

我在三个子菜单中有一个相同的链接,所以当我单击其中一个时,它会高亮显示最后一个菜单

这是我的密码:-

var str = location.href.toLowerCase();
        $("#menu li a").each(function () {
            if (str.indexOf($(this).attr("href").toLowerCase()) > -1) {
                 $("li.activelink").removeClass("activelink");
                 $(this).parent().addClass("activelink");
                 $(this).parents("#menu ul").parent().addClass("activelink");
             }
         });
         $("li.activelink").parents().each(function () {
             if ($(this).is("li")) {
                 $(this).addClass("activelink");
             }
         });
         $("li.activelink").parents("#menu ul").parent().each(function () {
             if ($(this).is("li")) {
                 $(this).addClass("activelink");
             }
         });
         $("#menu li .para1 a").each(function () {
             if (str.indexOf($(this).attr("href").toLowerCase()) > -1) {
                 $("li.activelink").removeClass("activelink");
                 $(this).parent().addClass("activelink");
                 $(this).parents().parent().addClass("activelink");
             }
         });
         $("li.activelink").parents().each(function () {
             if ($(this).is("li")) {
                 $(this).addClass("activelink");
             }
         }); 
看看这里

也可以在 请为相同的更新提供建议:这不是OP计划的问题。下面的代码无法解决此问题

我有过很多次这个问题。尝试以下CSS代码:

#menu > li:hover { background-color: red; }

将背景色声明替换为您自己的突出显示。

将JS和CSS也添加到提琴中,以再现问题。@anpsmn:Updated JS fiddle:-这不是我的解决方案,请阅读我的问题我在寻找什么。突出显示菜单无法解决我的问题..谢谢