layui合并table相同内的行

   <table border="1" id="table1" class="layui-table">
       <thead>
           <tr>
               <th><b>姓名</b></th>
               <th><b>项目</b></th>
               <th><b>任务</b></th>
               <th><b>日报</b></th>
               <th><b>备注</b></th>
           </tr>
       </thead>
       <tbody id="tbody">
           @{
               if (ViewBag.List != null && ViewBag.List.Count > 0)
               {
                   for (int i = 0; i < ViewBag.List.Count; i++)
                   {
                       <tr>
                           <td>@ViewBag.List[i].Username</td>
                           <td>@ViewBag.List[i].ProjectName</td>
                           <td>@ViewBag.List[i].TaskName</td>
                           <td>@ViewBag.List[i].Daily</td>
                           <td>@ViewBag.List[i].Remark</td>
                       </tr>
                   }
               }
           }
       </tbody>
   </table>
 <script>
     //合并table的相同内容行
     jQuery.fn.rowspan = function (colIdx) {
         return this.each(function () {
             var that;
             $('tr', this).each(function (row) {
                 $('td:eq(' + colIdx + ')', this).filter(':visible').each(function (col) {
                     if (that != null && $(this).html() == $(that).html()) {
                         rowspan = $(that).attr("rowSpan");
                         if (rowspan == undefined) {
                             $(that).attr("rowSpan", 1);
                             rowspan = $(that).attr("rowSpan");
                         }
                         rowspan = Number(rowspan) + 1;
                         $(that).attr("rowSpan", rowspan);
                         $(this).hide();
                     } else {
                         that = this;
                     }
                 });
             });
         });
     }
     //调用
     $(function () {
         $("#table1").rowspan(0);//合并第1列
         $("#table1").rowspan(1);//合并第2列
         $("#table1").rowspan(2);//合并第3列
     });
 </script>


效果如图:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值