jquery点击功能hide()后,下拉菜单无法打开; + e.stopPropagation

时间:2018-04-28 06:19:03

标签: jquery html

标题说的就是这一切。该功能可以工作1次,当我在菜单外单击时它会关闭,但是当我在菜单外单击后,菜单<div class="topnav" id="myTopnav"> <a href="slotenvervangen" class="active">Slotenvervangen</a> <a class="menulink" href="index"><span>Home</span></a> <a class="menulink" href="slotenopenen"><span>Sloten openen</span></a> <a class="menulink" href="inbraakbeveiliging"><span>Inbraakbeveiliging</span></a> <a class="menulink" href="contact"><span>Contact</span></a> <a href="javascript:void(0);" style="font-size:15px;" class="icon" onclick="myFunction()">&#9776;</a> </div> $(document).click(function(){ $(".menulink").hide(); }); /* tried one,two then ended up trying to use them all*/ $(".topnav,.icon,.menulink").click(function(e){ e.stopPropagation(); }); function myFunction() { var x = document.getElementById("myTopnav"); if(x.className === "topnav"){ x.className += " responsive"; }else{ x.className = "topnav"; } } 不再打开。有人可以帮我解决这个问题吗?谢谢你的时间

{{1}}

1 个答案:

答案 0 :(得分:0)

您需要在隐藏时点击选项时显示menulink

所以添加代码以在menulink

中显示myFunction
function myFunction() {
      $(".menulink").show();
    var x = document.getElementById("myTopnav");
    if (x.className === "topnav") {
        x.className += " responsive";
    } else {
        x.className = "topnav";
    }