1. 程式人生 > 其它 >jquery動態行合併通用jQuery外掛

jquery動態行合併通用jQuery外掛

//行合併外掛
jQuery.fn.rowspan = function(colIdx) { //封裝的一個JQuery小外掛
return this.each(function(){
var that;
$('tr', this).each(function(row) {
$('td:eq('+colIdx+')', this).each(function(col) {
if (that!=null && this.innerText == that.outerText) {
rowspan = $(that).attr("rowSpan");
if (rowspan == undefined) {
$(that).attr("rowSpan",1);
rowspan = $(that).attr("rowSpan");
}
rowspan = Number(rowspan)+1;
$(that).attr("rowSpan",rowspan);
$(that).css("line-height", 50 * rowspan + 'px');
$(this).hide();
} else {
that = this;
}
});
});
});
}

$("#dwgsTable").rowspan(0);

dwgsTable:table的ID

<table class="table table-bordered table-condensed" id="dwgsTable">
<thead>
<tr>
<th style="width: 45px">序號</th>
<th>專案名稱</th>
<th>單位工程名稱</th>
<th>專業</th>
<th>送審金額</th>
<th>協審人員</th>
<th>協審複核人員</th>
</tr>
</thead>
</table>