HTML:
<ul class="current">
<li>
<a href="#nogo"><b>Products</b>
<div class="select_sub show">
<ul class="sub">
<li class="sub_show"><a href="product/product.php">Add product</a></li>
</ul>
</div>
</a>
</li>
</ul>
<ul class="select">
<li>
<a href="#nogo"><b>Item</b>
<div class="select_sub">
<ul class="sub">
<li><a href="itea/item.php">Add Item</a></li>
</ul>
</div>
</a>
</li>
</ul>
jQuery的:
$("ul").click(function (e) {
e.preventDefault(); // if iI comment that line a href link work but navigation not work
var $this = $(this);
var $siblings = $(this).siblings();
$this.addClass("current").removeClass("select");
$this.find('.select_sub').addClass('show');
$siblings.removeClass("current").addClass('select');
$siblings.find('.select_sub').addClass('show');
});
如果我点击Add product
链接,此网址上会有重定向product/product.php
由于
答案 0 :(得分:0)
我的猜测是,当你说e.preventDefault()
时,你实际上是在告诉ul
默认,这没什么。尝试直接在链接上致电preventDefault()
。