Html:
<html ><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link rel="stylesheet" type="text/css" href="css/demo_20.css"/><script src="js/jquery-3.4.1.min.js"></script><script src="js/jquery_demo_20.js"></script></head><body> <table> <thead> <th>姓名</th><th>年龄</th><th>电话</th> </thead> <tbody> <tr>Css:* { padding:0; margin:0;}body { font-size:14px; padding:100px;}table { border-collapse:collapse;}th { border-bottom:1px solid #000; padding:5px 15px;}td { padding:5px 15px;}.demo { background:#eee; cursor:pointer;}.selected { background:#ccc;}Js:
$(document).ready(function(){ $(".demo").click(function(){ $(this).toggleClass("selected") .siblings('.child_'+this.id).toggle(); }).click();});