Jquery Wordpress折叠菜单保持不展开

Jquery Wordpress折叠菜单保持不展开,jquery,wordpress,menu,Jquery,Wordpress,Menu,目前我正在这个网站上工作: 问题是,单击链接后,子菜单保持不展开 这是放置在header.php中的代码 <script> $(document).ready(function(){ $('.menu .dropdown a').click(function(e){ if ($(this).parent().children('.sub-menu').is(':visible')) { $(this).parent()

目前我正在这个网站上工作:

问题是,单击链接后,子菜单保持不展开

这是放置在header.php中的代码

<script>
 $(document).ready(function(){
     $('.menu .dropdown a').click(function(e){  
          if ($(this).parent().children('.sub-menu').is(':visible')) {
               $(this).parent().children('.sub-menu').toggle();
          } else {
               $(this).parent().children('.sub-menu').toggle();
          }
     });
});
</script>

$(文档).ready(函数(){
$('.menu.dropdown a')。单击(函数(e){
if($(this).parent().children('.sub-menu')。是(':visible')){
$(this).parent().children('.sub-menu').toggle();
}否则{
$(this).parent().children('.sub-menu').toggle();
}
});
});

我想这只是一件小事,我真的很感谢你的帮助!谢谢

如果您希望在单击后和页面更改后子菜单展开,则需要将其切换为doc.ready,而不是单击

$(document).ready(function() {
    $("li.current-menu-item").closest(".sub-menu").toggle();
});

谢谢你的快速回复,但我不能让它像这样工作。