我是jQuery的初學者。我創建了自己的下拉列表中,而問題是,當我創建e.preventDefault();
它適用於孩子太下拉,我想避免jQuery e.prevent默認適用於兒童li
HTML
<div id="wrapper" class="container">
<nav>
<ul>
<li><a href="">ABOUT PGP</a></li>
<li class="parent"><a href="#">SERVICES</a>
<ul class="sub-menu">
<li><a href="">Overview</a></li>
<li><a href="">Industry Expertise</a></li>
<li><a href="">Cross-Cultural Expertise</a></li>
<li><a href="">Value Proposation</a></li>
</ul>
</li>
<li class="parent"><a href="">TRANSACTIONAL EXPERIENCE</a>
<ul class="sub-menu">
<li><a href="">Select Transactions</a></li>
<li><a href="">Prior Transactions</a></li>
</ul>
</li>
<li class="parent"><a href="#">TEAM</a>
<ul class="sub-menu">
<li><a href="index.html">Professionals</a></li>
<li><a href="">Board of Directors</a></li>
<li><a href="">Advisory Board</a></li>
</ul>
</li>
<li class="parent"><a href="">MEDIA</a>
<ul class="sub-menu">
<li><a href="" class="long">PGP Press Releases & Announcements</a></li>
<li><a href="" class="long">PGP In The Newss</a></li>
</ul>
</li>
<li><a href="">STRATEGIC PARTNERS</a></li>
<li><a href="">CONTACT US</a></li>
</ul>
</nav>
</div>
jQuery的
<script>
$(function(){
$('li.parent').bind('click', function(e){
e.preventDefault();
$(this).children('ul.sub-menu').fadeIn(800);
});
});
</script>
難道有人請給我一個暗示我做錯了什麼嗎?
你不能只用'$('li.parent> a')'嗎?即。目標只包含在'父' – billyonecan