为我的菜单使用无序列表..我已经选择了点击工作,但我无法找出仅针对特定列表的选择。我现在拥有它的方式,它扩展/折叠具有特定类的所有列表,但我只想在我点击的类中使用它。
这是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>
答案 0 :(得分:0)
除了符合非标准的HTML之外,这应该为您提供所需的功能
$("#loginTitle").click(function() {
$(".login-holder").find("li").slideToggle("medium");
});
您不应对多于1个元素使用相同的ID“loginTitle”,尝试将其切换到css类并将上面的选择器更改为.loginTitle