JQuery實現表格裡面的相同內容的單元格合併
<script type="text/javascript">
jQuery.fn.rowspan = function (colIdx) { //封裝的一個JQuery小外掛
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);//傳入的引數是對應的列數從0開始,哪一列有相同的內容就輸入對應的列數值
$("#table1").rowspan(2);
});
</script>