最近我的jquery代码有问题。我试图使用jquery find方法从html中获取元素,但它不起作用。我试过更改元素名称,但我仍然无法找到我的错误。
以下是html代码:
<div class="navbar-collapse collapse">
<nav>
<ul class="nav navbar-nav navbar-right">
<li class = "dropdown"><a href="#" class = "dropdown-toggle" data-toggle = "dropdown"><span>About Us</span><b class = "caret"></b></a>
<ul class = "dropdown-menu">
<li data-slide = '1'><a href = "#">Philosophy</a></li>
<li><a href = "#">Founding Members</a></li>
<li><a href = "#">Committee</a></li>
<li><a href = "#">Code of Ethics</a></li>
</ul>
</li>
<li data-slide='2'><a href="#">Digital Ecosystem</a></li>
<li data-slide='3'><a href="#">Fellow & Members</a></li>
<li data-slide='4'><a href="#">SIGs</a></li>
<li data-slide='5'><a href="#">Local Chapters</a></li>
<li data-slide="7"><a href="#">Events</a></li>
<li data-slide="8"><a href="#">Our Service</a></li>
<li>
<a href="#" onClick="window.open('logout.php','_self','width=400,height=200,toolbar=yes, location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes, resizable=yes')">
<?php
if (isset($_SESSION['CurrentUser'])) {
echo "Log Out";
}
?>
</a>
</li>
<li>
<a href="#" onClick="window.open('login.php','_self','width=400,height=200,toolbar=yes, location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes, resizable=yes')">
<?php
if (!isset($_SESSION['CurrentUser'])) {
echo "Login/Register";
}
?>
</a>
</li>
</ul>
</nav>
</div>
我也包含了我的jquery代码:
var links = $('.nav, .navbar-nav, .navbar-right').find('li');
实际上代码的作用是,一旦找到'li'html元素,每次点击'li'元素时它就会滑动页面。现在,如果我点击“li”元素,我的页面就不会滚动到所选页面。如果有人在那里解决我的问题会很棒。
答案 0 :(得分:0)
试试这个(如果你真的想要“链接”标签):
var links = $('.nav.navbar-nav.navbar-right').find('a');