/*jslint browser: true*/
/*global $, jQuery, alert*/
$("#menu-toggle").click(function (e) {
"use strict";
e.preventDefault();
$("#wrapper").toggleClass("toggled");
});
$("#menu-toggle-2").click(function (e) {
"use strict";
e.preventDefault();
$("#wrapper").toggleClass("toggled-2");
$('#menu ul').hide();
});
function initMenu() {
$('#menu ul').hide();
$('#menu ul').children('.current').parent().show();
//$('#menu ul:first').show();
$('#menu li a').click(
function() {
var checkElement = $(this).next();
if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
return false;
}
if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
$('#menu ul:visible').slideUp('normal');
checkElement.slideDown('normal');
return false;
}
}
);
}
$(document).ready(function() {initMenu();
});
<div id="sidebar-wrapper">
<ul class="sidebar-nav nav-pills nav-stacked" id="menu">
<li class="active">
<a href="newfeeds.html" id="home" data-toggle="nav-pills"><span class="fa-stack fa-lg pull-left"><i class="fa fa-dashboard fa-stack-1x "></i></span>News Feed</a>
<ul class="nav-pills nav-stacked" style="list-style-type:none;">
</ul>
</li>
<li>
<a href="#"><span class="fa-stack fa-lg pull-left"><i class="fa fa-envelope fa-stack-1x "></i></span> Messages</a>
</li>
<li>
<a href="#"> <span class="fa-stack fa-lg pull-left"><i class="glyphicon glyphicon-equalizer fa-stack-1x "></i></span>Activity</a>
<ul class="nav-pills nav-stacked" style="list-style-type:none;">
<li><a href="profile.html"><span class="fa-stack fa-lg pull-left"><i class="glyphicon glyphicon-inbox fa-stack-1x "></i></span>Posts</a></li>
<li><a href="#"><span class="fa-stack fa-lg pull-left"><i class="fa fa-paper-plane-o fa-stack-1x "></i></span>Recent Activity</a></li>
</ul>
</li>
<li>
<a href="profilesetting.html" id="profilesetting" data-toggle="nav-pills"><span class="fa-stack fa-lg pull-left"><i class="glyphicon glyphicon-cog fa-stack-1x "></i></span>Profile Settings</a>
</li>
<li>
</ul>
</div><!-- /#sidebar-wrapper -->
我在Bootstrap中使用它。当我点击个人资料设置然后返回新闻Feed时,它无法正常工作。我猜jquery错了。我不是试图学习jquery的jquery专家。我有谷歌,但没有给我正确的答案。