非常简单..
<script src="jquery.js"></script>
<div id="navigation">
<p><a href="#" id="toggle">Menu</a></p>
<ul id="menu">
<li><a href="/#" class="book-campaigns">Menu 1</a><ul>
<li><a href="#" class="lol">lol</a></li><li><a href="#" class="lol">lol2</a></li><li><a href="#" class="lol">lol</a></li><li><a href="#" class="lol">lol2</a></li>
</ul></li>
<li><a href="/#" class="book-campaigns">Menu 2</a><ul>
<li><a href="#" class="lol">lol</a></li><li><a href="#" class="lol">lol2</a></li><li><a href="#" class="lol">lol</a></li><li><a href="#" class="lol">lol2</a></li>
</ul></li>
<li><a href="/#" class="book-campaigns">Menu 3</a><ul>
<li><a href="#" class="lol">lol</a></li><li><a href="#" class="lol">lol2</a></li><li><a href="#" class="lol">lol</a></li><li><a href="#" class="lol">lol2</a></li>
</ul></li>
<li><a href="/#" class="book-campaigns">Menu 4</a><ul>
<li><a href="#" class="lol">lol</a></li><li><a href="#" class="lol">lol2</a></li><li><a href="#" class="lol">lol</a></li><li><a href="#" class="lol">lol2</a></li>
</ul></li>
这将是您的 HTML 容器等,在此之下您将需要您的 javascript 来控制隐藏和更改!如果你觉得艺术,你也可以添加一些造型!
<script>
var showMenuText = $('#toggle').text();
var hideMenuText = 'Close';
$('#navigation ul').hide();
$('#navigation ul a.active+ul').show();
hideMenu = function() {
$('#navigation ul#menu').hide();
$('#navigation').removeClass('open');
$('#toggle').text(showMenuText);
}
$('#toggle').click(function(event){
event.stopPropagation(); event.preventDefault();
$('#navigation ul#menu').toggle();
$('#navigation').toggleClass('open');
var toggleText = $('#toggle').text();
(toggleText == showMenuText) ? $(this).text(hideMenuText) : $(this).text(showMenuText);
});
$('ul#menu > li > a').click(function(event){
$this = $(this);
if( $this.hasClass('page') ) parent.location = $this.attr('href');
if( $this.hasClass('home') ) { parent.location = '/'; }
event.preventDefault(); event.stopPropagation();
if( $this.hasClass('active') ) var justclosed = true;
$('a.active').removeClass('active').next('ul').hide();
if(!justclosed) $this.addClass('active').next('ul').show();
});
</script>
这是一个简单的 HTML 示例,您可以按照自己喜欢的方式执行它。