python rowspan_通过jquery还原含有rowspan、colspan的table的实现方法

需求

把含有rowspan、colspan的table还原。

例如原table为:

还原后的table为:

代码原理

对table进行遍历,如果td的rowspan属性值大于1,则给当前的td的父元素的兄弟元素添加td,如果td的colspan属性值大于1,则在当前的td元素后添加td

代码如下:

//本文首发博客园:http://artwl.cnblogs.com(2012/02/08)jQuery.fn.RevertTable=function(){

$("tr",this).each(function(trindex,tritem){

$(tritem).find("td").each(function(tdindex,tditem){

var rowspanCount=$(tditem).attr("rowspan");

var colspanCount=$(tditem).attr("colspan");

var value=$(tditem).text();

var newtd="

"+value+"";

if(rowspanCount>1){

var parent=$(tditem).parent("tr")[0];

while(rowspanCount-->1){

$(parent).next().prepend(newtd);

parent=$(parent).next();

}

$(tditem).attr("rowspan",1);

}

if(colspanCount>1){

while(colspanCount-->1){

$(tditem).after(newtd);

}

$(tditem).attr("colspan",1);

}

});

});

}

在线演示 http://demo.jb51.net/js/2012/jquery_demo/jquery_rowspan_colspan_table.html小结

本文只提供了还原含有rowspan、colspan的table的方案之一,欢迎大家测试讨论。

至于合并表格单元格网上已经有了代码:

原文标题:jQuery colspan and rowspan table using cell break

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值