我在下面有以下代码和 jsFiddle 链接。在我看来,我的代码应该可以工作,它会找到正确的 li 标签并禁用默认操作,问题是它会在不应该的情况下将其重复到子元素中。你能解释一下吗?
http://jsfiddle.net/andyjh07/6HAvV/
HTML:
<ul id="nav">
<li class=""><a href="home.htm">Home</a>
</li>
<li class="nav_parent"><a href="our-projects.htm">Our Projects</a>
<ul class="nav_child">
<li class=""><a href="the-palms-at-corozal.htm">The Palms At Corozal</a>
</li>
<li class=""><a href="the-lakes-at-consejo.htm">The Lakes At Consejo</a>
</li>
</ul>
</li>
<li class="nav_parent"><a href="about-us.htm">About Us</a>
<ul class="nav_child">
<li class=""><a href="who-we-are.htm">Who We Are</a>
</li>
<li class=""><a href="other-projects.htm">Other Projects</a>
</li>
<li class=""><a href="partners.htm">Partners</a>
</li>
</ul>
</li>
<li class="nav_parent"><a href="about-belize.htm">About Belize</a>
<ul class="nav_child">
<li class=""><a href="general-info.htm">General Info</a>
</li>
<li class=""><a href="investing-in-belize.htm">Investing In Belize</a>
</li>
<li class=""><a href="useful-links.htm">Useful Links</a>
</li>
</ul>
</li>
<li class=""><a href="news.htm">News Articles</a>
</li>
<li class=""><a href="contact-us.htm">Contact Us</a>
</li>
</ul>
jQuery:
$(document).ready(function () {
$('ul#nav li:eq(1)').addClass('removeLink');
$('.removeLink').click(function (e) {
e.preventDefault();
});
});