function show_l(name1,name2){ $(name2).each(function(){ if ($(this).index()>2) { $(this).hide(); }; }); var index=1; $(name1).on('click',function(){ if (index == 1) { $(this).find('span').text('收起'); $(name2).each(function(){ $(this).show(); }); $(this).addClass('on'); index=2; }else if(index == 2){ $(this).find('span').text('展开'); $(name2).each(function(){ if ($(this).index()>2) { $(this).hide(); }; }); $(this).removeClass('on'); index=1; } }) } show_l('.y_lpyszsq a','.y_lpysz_table tbody tr');