5

js中怎么循环输出两个table两个table的输出

 function searchSpecific(headCount){
    //查询每个月具体扣税
    $.ajax({
        type: 'POST',
        url: 'personVoid_searchPersons.action',
        data: {
            headCount: headCount
        },
        dataType: 'JSON',
        success: function(data){
         var today = new Date();
         var year = today.getFullYear();
         for(var b=year; b>=2011; b--){
             var str2 = '<table  align="center" border=1 cellpadding="0" cellspacing="0" bordercolor="#BBDDFF" width="600px"><tr><th colspan=6>'+b+'</th></tr><tr><th>Month</th><th>WorkDay</th><th>Fss</th><th>FssEmployer</th><th>Time</th><th>InvoiceNo</th></tr>';  
              for(var a=1;a<13;a++){
                  var flag = true;
                  $.each(data,function(i,row){
                      if(b == row.year && a == row.month){
                          if(row.invoiceNo.length == 1){

                             str2 +=('<td align="center" height="30px">' + row.month + '</td><td align="center" height="30px">' + row.workDay + '</td><td align="center" height="30px">'+row.fss + '</td><td align="center" height="30px">'+row.fssEmployer + '</td><td align="center" height="30px">'+row.time + '</td><td height="30px">'+row.invoiceNo[0] + '</td></tr>');
                        }else{
                            str2 +=('<td  height="30px" align="center" rowspan='+row.invoiceNo.length+'>' + row.month + '</td><td  height="30px" align="center" rowspan ='+row.invoiceNo.length+'>' + row.workDay + '</td><td  height="30px" align="center" rowspan ='+row.invoiceNo.length+'>' + row.fss + '</td><td  height="30px" align="center" rowspan ='+row.invoiceNo.length+'>' + row.fssEmployer + '</td><td  height="30px" align="center" rowspan ='+row.invoiceNo.length+'>' + row.time + '</td><td>'+row.invoiceNo[0] + '</td>');
                            str2 += '</tr>';

                            $.each(row.invoiceNo, function(j,val){
                                if(j > 0){
                                    str2 +=('<tr><td>'+row.invoiceNo[j] + '</td></tr>');
                                }
                            });
                        }

                        flag = false;
                        return false;
                    }
                });

                if(flag){
                    str2 += '<tr><td align="center">'+a+'</td><td align="center">0</td><td align="center">0.0</td><td align="center">0.0</td><td align="center">--</td><td align="center">--</td></tr>';
                    }
            }
            str2 += '</table><br/>';

            $('#fssSpecific').append(str2);
         }
      }
    }); 

}

这个只能一个table一个table的输出

查看全部
qq_20261707
默笙仁
2015/07/21 06:05
  • 循环输出两个table
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

5个回复