Javascript Jquery向上滑动和向下滑动切换
我正在使用ASP.NETMVC4。我的razor视图中有一个嵌套列表,如下所示:Javascript Jquery向上滑动和向下滑动切换,javascript,jquery,html,css,asp.net-mvc-4,Javascript,Jquery,Html,Css,Asp.net Mvc 4,我正在使用ASP.NETMVC4。我的razor视图中有一个嵌套列表,如下所示: <ul class="nav" id="product-cat-menu"> <li><a href="/Products/Index?category=2002">Dental <i class="fa fa-plus-square-o rightdown"></i></a> <ul>
<ul class="nav" id="product-cat-menu">
<li><a href="/Products/Index?category=2002">Dental <i class="fa fa-plus-square-o rightdown"></i></a>
<ul>
<li><a href="/Products/Index?category=2004">Materials <i class="fa fa-plus-square-o rightdown"></i></a>
<ul>
<li><a href="/Products/Index?category=2011">Pulp<i class="fa fa-plus-square-o rightdown"></i></a></li>
<li><a href="/Products/Index?category=3011">Etchants <i class="fa fa-plus-square-o rightdown"></i></a>
</ul>
<li><a href="/Products/Index?category=2006">Medicines <i class="fa fa-plus-square-o rightdown"></i></a>
<ul>
<li><a href="/Products/Index?category=2011">Pulp<i class="fa fa-plus-square-o rightdown"></i></a></li>
<li><a href="/Products/Index?category=3011">Etchants <i class="fa fa-plus-square-o rightdown"></i></a>
</ul>
</li>
</ul>
</li>
<li><a href="/Products/Index?category=2003">Oral <i class="fa fa-plus-square-o rightdown"></i></a></li>
</ul>
jQuery就像:
$(document).ready(function () {
$("#product-cat-menu a").click(function () {
$("#product-cat-menu ul").slideUp();
if (!$(this).next().is(":visible")) {
$(this).next().slideDown();
}
});
});
问题是,当单击li
时,它会在子列表中向下滑动,但在进入控制器操作后,它会向上滑动。我想在页面刷新后显示向下滑动部分
为此,我还尝试了以下代码:
$(document).ready(function () {
$("#product-cat-menu a .rightdown").click(function() {
//...........
});
});
但是这不起作用。我认为您需要防止html锚定标记的默认行为(
我还有一个疑问,当单击列表材料或药物时,列表是向上滑动的,我想在这个循环中向下滑动…我不确定您的意思,您能解释一下吗。
$(document).ready(function () {
$("#product-cat-menu a .rightdown").click(function() {
//...........
});
});
$(document).ready(function () {
$("#product-cat-menu a").click(function (evt) {
evt.preventDefault();
$("#product-cat-menu ul").slideUp();
if (!$(this).next().is(":visible")) {
$(this).next().slideDown();
}
});
});