jquery.table.rowspan.js 表格自动合并单元格插件
来源:互联网 发布:智能中医处方软件 编辑:程序博客网 时间:2024/05/17 01:09
</pre>日常开发中,经常遇到表格里需要自动合并单元格,考虑到写服务器控件比较消耗性能,因些还是把这种工作交给客户端Javascript去做吧,基于习惯用jquery框架,所以封装了一个Jquery插件。<p></p><p>1.新创建一个js文件,命名为jquery.table.rowspan.js</p><pre code_snippet_id="1648177" snippet_file_name="blog_20160415_1_9842811" name="code" class="javascript">(function ($) { $.fn.extend({ //表格合并单元格,colIdx要合并的列序号,从0开始 "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; } }); }); }); } });})(jQuery);
2.使用实例
<!DOCTYPE html><html><head><title>表格单元格合并Demo</title> <script src="Scripts/jquery-1.7.1.min.js" type="text/javascript"></script> <script type="text/javascript" src="Scripts/jquery.table.rowspan.js"></script> <script type="text/javascript"> function initLoad() { $("#tbListTM").rowspan(0); //第一列合并 $("#tbListTM").rowspan(1);//第二列合并 } $(document).ready(function () { initLoad(); }); </script> <style> .Nlist_con table { border-left: 1px solid #c9c9c9; border-top: 1px solid #c9c9c9; border-collapse: collapse; } .Nlist_con table th { border-right: 1px solid #c9c9c9; border-bottom: 1px solid #c9c9c9; background: #ececec; padding: 10px 5px; font-size: 14px; color: #2586d8; font-family: "宋体"; } .Nlist_con table td { border-right: 1px solid #c9c9c9; border-bottom: 1px solid #c9c9c9; background: #fff; padding: 6px 3px; font-size: 12px; line-height: 20px; color: #676767; } .Nlist_con table td a { text-decoration: none; color: #2586d8; cursor: pointer; } .Nlist_con table td a:hover { text-decoration: underline; color: #2586d8; } </style></head><body> <div class="Nlist_con"> <table border="1" cellspacing="1" cellpadding="0" width="100%" id="tbListTM"> <tr align="center"> <th> 发展领域 </th> <th> 发展要素 </th> <th style="width:60px"> 年度 </th> <th style="width:100px"> 评价内容 </th> <th> 分值 </th> <th> 评价办法 </th> </tr> <tr> <td style="text-align: center"> 学校发展目标 </td> <td> 1.学校有先进办学理念,办学目标符合教育改革发展要求,符合学校实际和发展规律,体现出阶段性、递进性和自身特别。 </td> <td> <span id="ctl00_ContentPlaceHolder1_rptListTM_ctl00_lblND">2015</span> </td> <td> ee </td> <td> 2 </td> <td>办法1</td> </tr> <tr> <td style="text-align: center"> 学校发展目标 </td> <td> 1.学校有先进办学理念,办学目标符合教育改革发展要求,符合学校实际和发展规律,体现出阶段性、递进性和自身特别。 </td> <td> <span id="ctl00_ContentPlaceHolder1_rptListTM_ctl01_lblND">2016</span> </td> <td> dd </td> <td> 2 </td> <td>办法2</td> </tr> <tr> <td style="text-align: center"> 学校发展目标 </td> <td> 1.学校有先进办学理念,办学目标符合教育改革发展要求,符合学校实际和发展规律,体现出阶段性、递进性和自身特别。 </td> <td> <span id="ctl00_ContentPlaceHolder1_rptListTM_ctl02_lblND">2017</span> </td> <td> ff </td> <td> 2 </td> <td>办法3</td> </tr> <tr> <td style="text-align: center"> 学校发展目标 </td> <td> 2.培养目标符合教育方针。注重促进学生、教师主动发展和个性特长的发展,体现学校的个性与特色。 </td> <td> <span id="ctl00_ContentPlaceHolder1_rptListTM_ctl03_lblND">2015</span> </td> <td></td> <td> 0 </td> <td></td> </tr> <tr> <td style="text-align: center"> 学校发展目标 </td> <td> 2.培养目标符合教育方针。注重促进学生、教师主动发展和个性特长的发展,体现学校的个性与特色。 </td> <td> <span id="ctl00_ContentPlaceHolder1_rptListTM_ctl04_lblND">2016</span> </td> <td></td> <td> 0 </td> <td></td> </tr> <tr> <td style="text-align: center"> 学校发展目标 </td> <td> 2.培养目标符合教育方针。注重促进学生、教师主动发展和个性特长的发展,体现学校的个性与特色。 </td> <td> <span id="ctl00_ContentPlaceHolder1_rptListTM_ctl05_lblND">2017</span> </td> <td></td> <td> 0 </td> <td></td> </tr> </table> </div></body></html>3.效果演示
4.源码下载
源码下载 1 0
- jquery.table.rowspan.js 表格自动合并单元格插件
- JS:jquery插件表格单元格合并.
- 表格,合并单元格colspan,rowspan
- table合并单元格(Jquery 插件
- JavaScript JS合并单元格 rowspan
- table合并单元格colspan和rowspan
- table合并单元格colspan和rowspan
- table合并单元格colspan和rowspan
- table合并单元格colspan和rowspan
- table合并单元格colspan和rowspan
- table合并单元格colspan和rowspan
- table合并单元格colspan和rowspan
- table合并单元格colspan和rowspan
- table合并单元格colspan和rowspan
- 合并table相同单元格的jquery插件
- table合并单元格(Jquery 插件)
- 合并table相同单元格的jquery插件
- table表格--合并单元格
- Django Channels 入门指南
- Python知识结构
- 获取Android设备唯一标识码
- iOS 真机调试
- 事务隔离级别详解
- jquery.table.rowspan.js 表格自动合并单元格插件
- phpstorm 10 注册码 汉化包
- 添加遮罩,自定义控件(view)的显示范围
- MDB application bea_wls9_async_response is NOT connected to mesagingsystem
- 桶排序
- ProgressBar的使用
- 寒门难再出贵子
- 使用phpqrcode生成某一个页面的二维码
- Qt网络编程之一http