jquery动态合并单元格-亲测有效
程序员文章站
2024-02-28 19:12:22
...
<script type="text/javascript">
$(document).ready(function(){
heBingFunction("#Table");//传入的table的id
})
function heBingFunction(tableObj){
var tr = $(tableObj).find("tbody tr");
var td = $(tableObj).find("tbody tr:eq(0) td");
for(var j=0;j<td.length;j++){
for(var i=1; i<tr.length; i++){
if($(tableObj).find("tr:eq("+i+")").find("td:eq("+j+")").text()==$(tableObj).find("tr:eq("+(i-1)+")").find("td:eq("+j+")").text()){
console.log($(tableObj).find("tr:eq("+i+")").find("td:eq("+j+")").text());
var t = i-1;
while($(tableObj).find("tr:eq("+i+")").find("td:eq("+j+")").text()==$(tableObj).find("tr:eq("+t+")").find("td:eq("+j+")").text()){
$(tableObj).find("tr:eq("+i+")").find("td:eq("+j+")").attr("style","display:none");
var rosVal = parseInt($(tableObj).find("tr:eq("+t+")").find("td:eq("+j+")").attr("rowspan"));
if(rosVal<=(i-t)){
$(tableObj).find("tr:eq("+t+")").find("td:eq("+j+")").attr("rowspan",rosVal+1);
};
i++;
};
};
};
}
};
</script>