左侧菜单练习
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <script src="jquery-3.4.1.js"></script> <script> function f(self) { $(self).next().removeClass("hide"); $(self).parent().siblings().children(".son").addClass("hide"); } </script> <style> .div1{ width: 100%; height: 1000px; } .menu{ float: left; background-color: navajowhite; width: 20%; height: 500px; } .content{ float: left; background-color: #dec7f4; width: 80%; height: 500px; } .title{ background-color: #339900; line-height: 30px; } .hide{ display: none; } </style> </head> <body> <div class="div1"> <div class="menu"> <div class="item"> <div class="title" onclick="f(this)">菜单一</div> <div class="son hide" > <div>111</div> <div>222</div> <div>333</div> </div> </div> <div class="item"> <div class="title" onclick="f(this)">菜单二</div> <div class="son hide"> <div>111</div> <div>222</div> <div>333</div> </div> </div> <div class="item"> <div class="title" onclick="f(this)">菜单三</div> <div class="son hide"> <div>111</div> <div>222</div> <div>333</div> </div> </div> </div> <div class="content"></div> </div> </body> </html>