首页 > Web开发 > 详细

基于JQuery实现相同内容合并单元格[转]

时间:2015-08-29 13:59:47      阅读:226      评论:0      收藏:0      [点我收藏+]
<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>

技术分享

基于JQuery实现相同内容合并单元格[转]

原文:http://www.cnblogs.com/liuswi/p/4769049.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!