1. 程式人生 > >左側菜單

左側菜單

ldr splay html har this lang scrip lan addclass

代碼示例:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.hide{
display: none;
}
</style>
</head>
<body>
<div>
<div class="menu">菜單一</div>
<div class="con hide">
<p>11111</p>
<p>22222</p>
<p>33333</p>
<p>44444</p>
</div>
</div>

<div>
<div class="menu">菜單二</div>
<div class="con hide">
<p>11111</p>
<p>22222</p>
<p>33333</p>
<p>44444</p>
</div>
</div>

<div>
<div class="menu">菜單三</div>
<div class="con hide">
<p>11111</p>
<p>22222</p>
<p>33333</p>
<p>44444</p>
</div>
</div>
<script src="jquery-3.2.1.js"></script>
<script>
$(function () {
bindclick();
});
function bindclick() {
$(‘.menu‘).click(function () {
$(this).next().removeClass(‘hide‘).parent().siblings().children(‘.con‘).addClass(‘hide‘)
})
}
</script>
</body>
</html>

左側菜單