合併表格中同一列中相同的內容

<script type="text/javascript">
$(function(){
        
        _w_table_rowspan("#apply_company",1);//第一個參數:表格的ID 
                                             //第二個參數:表格的第一列(根據本身需求而定)   
        
    });
function _w_table_rowspan(_w_table_id,_w_table_colnum){
          _w_table_firsttd = "";
          _w_table_currenttd = "";
          _w_table_SpanNum = 0;
          //注意1:  tr th: (根據本身需求修改)
          _w_table_Obj = $(_w_table_id + " tr th:nth-child(" + _w_table_colnum + ")");
          _w_table_Obj.each(function(i){
           if(i==0){
            _w_table_firsttd = $(this);
            _w_table_SpanNum = 1;
           }else{
            _w_table_currenttd = $(this);
            if(_w_table_firsttd.text()==_w_table_currenttd.text()){
             _w_table_SpanNum++;
             _w_table_currenttd.hide(); //remove();
             _w_table_firsttd.attr("rowSpan",_w_table_SpanNum);
            }else{
             _w_table_firsttd = $(this);
             _w_table_SpanNum = 1;
            }
           }
          });
         }

</script>


<table id="apply_company" cellpadding="0" cellspacing="0" width="100%" border="0"  >
    <tr>
        <th></th>    //這裏與 注意1 相對應
   </tr>

</table>



最後效果以下:

相關文章
相關標籤/搜索