展开/折叠 jquery 菜单(找不到正确的选择器)
在我的菜单中使用无序列表..我已经获得了单击工作的选择,但我无法弄清楚仅特定列表的选择。我现在的方式是,它展开/折叠具有特定类的所有列表,但我只想将它放在我单击的类上。
这是 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
除了不符合标准的 HTML 之外,这应该可以为您提供所需的功能。
您不应该对超过 1 个元素使用相同的 ID“loginTitle”,尝试将其切换到 css 类并将上面的选择器更改为
。登录标题
Aside from the non-standards compliant HTML, this should give you the functionality you want
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