我有一个正在使用 jquery 的垂直菜单。HTML和Jquery如下:
HTML:
<div id="menu">
<ul class="navmenu">
<li>
<div class="menutop menusingle">
<a id="A1" runat="server" href="~/View.aspx?pg=aboutus" >About Us </a></div>
</li>
<li>
<div class="menutop">
<a href="#">Courses</a><div class="toggle">
+</div>
</div>
<ul class="submenu">
<li><a id="A6" runat="server" href="~/View.aspx?pg=SoftwareIT">Software /IT</a></li>
<li><a id="A7" runat="server" href="~/View.aspx?pg=Telecommunication">Telecommunication</a></li>
<li><a id="A8" runat="server" href="~/View.aspx?pg=Hardware">Hardware & Networking</a></li>
<li><a id="A9" runat="server" href="~/View.aspx?pg=Sales">Sales & Marketing</a></li>
<li><a id="A10" runat="server" href="~/View.aspx?pg=BPO">BPO & Soft Skills</a></li>
</ul>
</li>
<li>
<div class="menutop">
<a href="#">Services</a><div class="toggle">
+</div>
</div>
<ul class="submenu">
<li><a id="A2" runat="server" href="~/View.aspx?pg=IndividualTraining">Individual Training </a></li>
<li><a id="A3" runat="server" href="~/View.aspx?pg=OncampusTraining ">On Campus Training </a></li>
<li><a id="A4" runat="server" href="~/View.aspx?pg=CorporateTraining">Corporate Training </a></li>
<li><a id="A5" runat="server" href="~/View.aspx?pg=Placement">Placement </a></li>
</ul>
</li>
<li>
<div class="menutop">
<a href="#">Trainings</a><div class="toggle">
+</div>
</div>
<ul class="submenu">
<li><a id="A11" runat="server" href="~/View.aspx?pg=FastTrack">FastTrack Training</a></li>
<li><a id="A12" runat="server" href="~/View.aspx?pg=Summer">Summer/Industrial</a></li>
<li><a id="A13" runat="server" href="~/View.aspx?pg=Weekend">Weekend Training</a></li>
</ul>
</li>
</ul>
</div>
单击 + 号会打开子菜单的抽屉。手动非常好。现在我想根据要求自动化它。我们在培训、课程和服务中进行了切换,因此如果当前 url 是服务的,那么服务菜单将自动打开。因为我们也有顶部导航和页脚导航。以上是左侧导航。
相同的 Jquery:
<script type="text/javascript">
$(document).ready(function() {
$('.toggle:not(.toggle-open)').addClass('toggle-closed').parents('li').children('ul').hide();
if ($.browser.msie) {
$('#menu ul.navmenu li:last-child .menutop').css('border-bottom', '1px solid #CCC');
}
$('.toggle').click(function() {
if ($(this).hasClass('toggle-open')) {
$(this).removeClass('toggle-open').addClass('toggle-closed').empty('').append('+').parents('li').children('ul').slideUp(250);
$(this).parent('.menutop').removeClass('menutop-open').addClass('menutop-closed');
} else {
$(this).parent('.menutop').removeClass('menutop-closed').addClass('menutop-open');
$(this).removeClass('toggle-closed').addClass('toggle-open').empty('').append('–').parents('li').children('ul').slideDown(250);
}
});
})
</script>
所以我需要一种 $('.toggle').click(function()
基于查询字符串调用 from cs 的方法。