JQuery合并表格单元格
生活随笔
收集整理的這篇文章主要介紹了
JQuery合并表格单元格
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
?
轉:http://www.cnblogs.com/xuguoming/p/3412124.html
JQuery合并表格單元格
一、需求
如果存在一個表格,想把其中某一列內容相同的部分合并單元格,用JQ動態如何操作,原始表格如下:
?
合并單元格之后的表格如下:
JQuery代碼如下:
1 <script type="text/javascript"> 2 jQuery.fn.rowspan = function (colIdx) { 3 return this.each(function () { 4 var that; 5 $('tr', this).each(function (row) { 6 $('td:eq(' + colIdx + ')', this).filter(':visible').each(function (col) { 7 if (that != null && $(this).html() == $(that).html()) { 8 rowspan = $(that).attr("rowSpan"); 9 if (rowspan == undefined) { 10 $(that).attr("rowSpan", 1); 11 rowspan = $(that).attr("rowSpan"); 12 } 13 rowspan = Number(rowspan) + 1; 14 $(that).attr("rowSpan", rowspan); 15 $(this).hide(); 16 } else { 17 that = this; 18 } 19 }); 20 }); 21 }); 22 } 23 $(document).ready(function () { 24 $("#table1").rowspan(0); 25 $("#table1").rowspan(2); 26 }); 27 </script>注:合并的是第一列和第三列,這個需求比較簡單,不許多大的闡述^_^結束!
轉載于:https://www.cnblogs.com/piaopiao7891/p/3412153.html
總結
以上是生活随笔為你收集整理的JQuery合并表格单元格的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Unix/Linux环境C编程入门教程(
- 下一篇: cannot be resolved o