如果 3 和 3.2 不是链接,下面的脚本可以正常工作,但我不知道如何在它们是链接时让它工作。
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title> - Test</title>
<script type='text/javascript' src='http://code.jquery.com/jquery-1.6.js'></script>
<style>
ul{
list-style-type: none;
padding: 0;
margin-left: 0;
font-weight: bold;
}
</style>
<script type='text/javascript'>
$(document).ready(function() {
$("#nav ul li:not(:has(li.current))").find("ul").hide().end() // Hide all other ULs
.click(function(e) {
if (this == e.target) {
$(this).children('ul').slideToggle('fast');
}
});
});
</script>
</head>
<body>
<div id="nav">
<ul>
<li><a href="javascript:void(0)">1</a></li>
<li><a href="javascript:void(0)">2</a></li>
<li><a href="javascript:void(0)">3</a>
<ul>
<li><a href="example.com">3.1</a></li>
<li><a href="javascript:void(0)">3.2</a>
<ul>
<li><a href="example.com">3.2.1</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="javascript:void(0)">4</a></li>
</ul>
</div>
</body>
</html>