展开/折叠 jquery 菜单(找不到正确的选择器)

发布于 2024-10-06 18:52:05 字数 2894 浏览 1 评论 0原文

在我的菜单中使用无序列表..我已经获得了单击工作的选择,但我无法弄清楚仅特定列表的选择。我现在的方式是,它展开/折叠具有特定类的所有列表,但我只想将它放在我单击的类上。

这是 jQuery

<script type="text/javascript">
    $(document).ready(function() {

        $(".login-holder > ul > #loginTitle").click(function() {
            $(".account-links:parent").slideToggle("medium");
        });
    });
</script>

这是 HTML

<div class="login-holder">

      <p><strong>Welcome, <%= ViewModel.Profile.Name.First %></strong></p>

      <ul class="account-links">
         <span id="loginTitle">User Options</span><br /><br />
         <li>
            <%= Html.ActionLink<EventController>( x => x.List(), "Events Near Me" )%>
         </li>
         <li>
            <%= Html.ActionLink<MyEventsController>( x => x.List(), "My Events" )%>
         </li>
         <li>
            <%= Html.ActionLink<AccountController>( x => x.Edit(), "My Profile" )%>
         </li>
         <li>
            <%= Html.ActionLink<ClubController>( x => x.List(), "Clubs Near Me" )%>
         </li>
         <li> 
            <%= Html.ActionLink<MyClubsController>( x => x.List(), "My Clubs" )%>
         </li>
         <li>
            <%= Html.ActionLink<AccountController>( x => x.ChangePassword(), "Change My Password" )%>
         </li>
         <li>
            <%= Html.ActionLink<DependantController>( x => x.List(), "My Dependants" ) %>
         </li>

      </ul>
   </div>
  <div class="login-holder">
     <ul class="account-links">
        <span id="loginTitle">Organizer Details<!--<span id="toggle" style="margin-left: 32px; padding-right: 10px;"></span>--></span><br /><br />
        <!--<div id="additions">-->
        <li>
           <%= Html.ActionLink<AccountController>( x => x.Organizer(), "Organizer Details" )%>
        </li>
        <li>
           <%= Html.ActionLink<EventController>( x => x.Edit( default(int?) ), "Post An Event" )%>
        </li>
        <li>
           <%= Html.ActionLink<EventAdminController>( x => x.List(), "Events Created By Me" ) %>
        </li>
        <li>
           <%= Html.ActionLink<ClubController>( x => x.Edit( default( int? ) ), "Create A Club" )%>
        </li>
        <li>
           <%= Html.ActionLink<ClubAdminController>( x => x.List( ), "Clubs Created By Me" )%>
        </li>
        <!--</div>-->
     </ul>
  </div>

Using an unordered list for my menu .. I've got the selection for the click working, but I can't figure out the selection for only the specific list. The way I have it now, it expands/collapses all the lists with the specific class, but I only want to have it on the class I've clicked in..

Here is the jQuery

<script type="text/javascript">
    $(document).ready(function() {

        $(".login-holder > ul > #loginTitle").click(function() {
            $(".account-links:parent").slideToggle("medium");
        });
    });
</script>

Here is the HTML

<div class="login-holder">

      <p><strong>Welcome, <%= ViewModel.Profile.Name.First %></strong></p>

      <ul class="account-links">
         <span id="loginTitle">User Options</span><br /><br />
         <li>
            <%= Html.ActionLink<EventController>( x => x.List(), "Events Near Me" )%>
         </li>
         <li>
            <%= Html.ActionLink<MyEventsController>( x => x.List(), "My Events" )%>
         </li>
         <li>
            <%= Html.ActionLink<AccountController>( x => x.Edit(), "My Profile" )%>
         </li>
         <li>
            <%= Html.ActionLink<ClubController>( x => x.List(), "Clubs Near Me" )%>
         </li>
         <li> 
            <%= Html.ActionLink<MyClubsController>( x => x.List(), "My Clubs" )%>
         </li>
         <li>
            <%= Html.ActionLink<AccountController>( x => x.ChangePassword(), "Change My Password" )%>
         </li>
         <li>
            <%= Html.ActionLink<DependantController>( x => x.List(), "My Dependants" ) %>
         </li>

      </ul>
   </div>
  <div class="login-holder">
     <ul class="account-links">
        <span id="loginTitle">Organizer Details<!--<span id="toggle" style="margin-left: 32px; padding-right: 10px;"></span>--></span><br /><br />
        <!--<div id="additions">-->
        <li>
           <%= Html.ActionLink<AccountController>( x => x.Organizer(), "Organizer Details" )%>
        </li>
        <li>
           <%= Html.ActionLink<EventController>( x => x.Edit( default(int?) ), "Post An Event" )%>
        </li>
        <li>
           <%= Html.ActionLink<EventAdminController>( x => x.List(), "Events Created By Me" ) %>
        </li>
        <li>
           <%= Html.ActionLink<ClubController>( x => x.Edit( default( int? ) ), "Create A Club" )%>
        </li>
        <li>
           <%= Html.ActionLink<ClubAdminController>( x => x.List( ), "Clubs Created By Me" )%>
        </li>
        <!--</div>-->
     </ul>
  </div>

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

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

发布评论

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

评论(1

紫﹏色ふ单纯 2024-10-13 18:52:05

除了不符合标准的 HTML 之外,这应该可以为您提供所需的功能。

$("#loginTitle").click(function() {
    $(".login-holder").find("li").slideToggle("medium");
});

您不应该对超过 1 个元素使用相同的 ID“loginTitle”,尝试将其切换到 css 类并将上面的选择器更改为 。登录标题

Aside from the non-standards compliant HTML, this should give you the functionality you want

$("#loginTitle").click(function() {
    $(".login-holder").find("li").slideToggle("medium");
});

You should not use the same ID "loginTitle" for more than 1 element, try switching it to a css class and change the selector above to .loginTitle

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文