且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

for循环中的jquery点击函数仅在最后一个循环中工作

更新时间:2022-02-17 09:28:44

这是错误的...

首先...隐藏所有详细信息并显示所有工人简单使用:

First... to hide all details and show all toglers simply use:

$('.details').hide();
$('.toggler').show();

然后为所有汇总定义点击函数:

And then define click function to all sumaries:

$('.summary').click(function(){
   if($('.toggler',this).html() == ' -'){
      $('.toggler',this).html(' +');
      $('.details',$(this).parent()).hide();
   }else{
      $('.toggler',this).html(' -');
      $('.details',$(this).parent()).show();
   }
});

将所有内容放入...

Put everything in...

$(function(){
   ...
});

应该可以。