<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<ul>
<li class="index">首页</li>
<ul class="sub-nav">
<li>首页1</li>
<li>首页2</li>
<li>首页3</li>
<li>首页4</li>
</ul>
</ul>
<script src="jquery.js"></script>
<script>
$(".index").click(function() {
// console.log($(".sub-nav:has(:hidden)"))
if($(".sub-nav:has(:hidden)").length == 0) {
$(".sub-nav").hide();
}else {
$(".sub-nav").show();
}
})
</script>
</body>
</html>