<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> <style> .hide{ display: none; } .show{ display: block; } </style> </head> <body> <div> <div class="b-1"> <div class="hang"> <span class="jian">-</span>aaa</div> <div class="show"> <ul> <li>1</li> <li>2</li> <li>3</li> </ul> </div> </div> <div class="b-1"> <div class="hang"> <span class="jian">-</span>aaa</div> <div class="show"> <ul> <li>1</li> <li>2</li> <li>3</li> </ul> </div> </div> <div class="b-1"> <div class="hang"> <span class="jian">+</span>aaa</div> <div class="hide"> <ul> <li>1</li> <li>2</li> <li>3</li> </ul> </div> </div> </div> </body> </html>
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script> <script type="text/javascript"> $(function() { $('.hang').on('click', function() { var status = $(this).find('.jian').text(); if (status == '-') { $(this).find('.jian').text('+'); $(this).next('div').addClass('show').removeClass('hide'); } else { $(this).find('.jian').text('-'); $(this).next('div').addClass('hide').removeClass('show'); } }) }) </script> <style> .hide{ display: none; } .show{ display: block; } </style> </head> <body> <div> <div class="b-1"> <div class="hang"> <span class="jian">-</span>aaa</div> <div class="hide"> <ul> <li>1</li> <li>2</li> <li>3</li> </ul> </div> </div> <div class="b-1"> <div class="hang"> <span class="jian">-</span>aaa</div> <div class="hide"> <ul> <li>1</li> <li>2</li> <li>3</li> </ul> </div> </div> <div class="b-1"> <div class="hang"> <span class="jian">+</span>aaa</div> <div class="show"> <ul> <li>1</li> <li>2</li> <li>3</li> </ul> </div> </div> </div> </body> </html>