jQuery .Toggle()不会隐藏div

时间:2014-07-01 12:50:01

标签: javascript jquery

我正试图在Jquery中切换下拉菜单的可见性。我的问题是,点击链接会显示菜单,再次点击它并不会隐藏它。

JQuery的:

$("#secondary_nav h3.user").click(function() {
  $("#user_actions").toggle();
}); 

 $(document).mouseup(function(e) {
    var container = $("#user_actions");

    // If the target of the click isn't the container &
    // nor is it a descendant of the container
    if (!container.is(e.target) && container.has(e.target).length === 0) {
      container.hide();
    }
  });

和HTML:

<div id='secondary_nav'>
              <div id='secondary_nav_inner'>
                <h3 class='messages'>
                  <a href="/admin/messages">Beskeder

                  </a>
                </h3>
                <h3 class='user'>
                  <span class='profile_picture'>
                    <img alt="B5da6b10 c94b 490d 885f 0827be92b47d" src="https://showmyday-development.s3.amazonaws.com/assets/000/000/759/admin_mini/b5da6b10-c94b-490d-885f-0827be92b47d" />
                  </span>
                 test (Testing)
                </h3>
                <div id='user_actions'>
                  <div id='user_actions_inner'>
                    <h4>Profil navigation</h4>
                    <ul>
                      <li><a href="/admin/guardians">Admins &amp; Brugere</a></li>
                      <li><a href="/admin/profile/edit">Rediger profil</a></li>
                      <li><a data-method="delete" href="/users/sign_out" rel="nofollow">Log ud</a></li>
                    </ul>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>

编辑:包含更多第二个JQuery方法

0 个答案:

没有答案