在 .toggle 中处理多个上下文菜单

发布于 2024-09-24 04:47:05 字数 724 浏览 0 评论 0原文

我在使这一切正常工作方面取得了进一步的进展,但是当我尝试添加一些代码,在单击一个代码时隐藏其他代码时,它预计第二次单击会再次隐藏。如何一次只显示一个菜单? PS 这些不是同级菜单。

$(function() {
  $("a[rel=tooltip]").tooltip({ position:"bottom" });
  $(".dd").toggle(function() {
      $("ul", this).show();
      $(this).addClass("on");
      $("ul a", this).click(function(e) {
         e.stopPropagation();
      });
      if $(".button1").click() {
        $("#contextMenu2, #contextMenu3").hide();
      };
      if $(".button2").click() {
        $("#contextMenu1, #contextMenu3").hide();
      };
      if $(".button3").click() {
        $("#contextMenu1, #contextMenu2").hide();
      };
    }, 
    function() { $("ul", this).hide(); $(this).removeClass('on'); }
  );
});

I'm further along in making this all work, but when I try to add some code that hides the others when one is clicked it expects a second click to hide again. How do I only show one menu at a time? PS These are not sibling menus.

$(function() {
  $("a[rel=tooltip]").tooltip({ position:"bottom" });
  $(".dd").toggle(function() {
      $("ul", this).show();
      $(this).addClass("on");
      $("ul a", this).click(function(e) {
         e.stopPropagation();
      });
      if $(".button1").click() {
        $("#contextMenu2, #contextMenu3").hide();
      };
      if $(".button2").click() {
        $("#contextMenu1, #contextMenu3").hide();
      };
      if $(".button3").click() {
        $("#contextMenu1, #contextMenu2").hide();
      };
    }, 
    function() { $("ul", this).hide(); $(this).removeClass('on'); }
  );
});

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

葵雨 2024-10-01 04:47:05

我让它按照我想要的方式工作。感谢这个线程 jQuery Toggle State

  $(".dd").click(function() {
    $("ul", ".dd").not(this).hide();
    $("ul", this).toggle();
  });
  $(".wrapper").click(function() {
    $("ul", ".dd").hide();
  });

I got this to work how I wanted it. Thanks to this thread jQuery Toggle State

  $(".dd").click(function() {
    $("ul", ".dd").not(this).hide();
    $("ul", this).toggle();
  });
  $(".wrapper").click(function() {
    $("ul", ".dd").hide();
  });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文