jquery合并表格

乜业
2023-12-01
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.0.js"></script>
		<script>
			function trowspan(tbl,col){
				var tdfst='',compare='',tdcur='',nums=1;
				tdarr=$(tbl+" tr td:nth-child("+col+")");
				tdarr.each(function(i){
					if(i==0){
						tdfst=$(this);
						compare=tdfst.text();
					}else{
						tdcur=$(this);
						if(compare==tdcur.text()){
							nums++;
							tdcur.hide();
							tdfst.attr("rowSpan",nums);
						}else{
							tdfst=$(this);
							compare=tdfst.text();
							nums=1;
						}
					}
				});
			}
			function tcolspan(tbl,row){
				var tdfst='',compare='',tdcur='',nums=1;
				tdarr=$(tbl+" tr:eq("+row+")").children().each(function(i){
					if(i==0){
						tdfst=$(this);
						compare=tdfst.text();
					}else{
						tdcur=$(this);
						if(compare==tdcur.text()){
							nums++;
							tdcur.hide();
							tdfst.attr("colSpan",nums);
						}else{
							tdfst=$(this);
							compare=tdfst.text();
							nums=1;
						}
					}
				});
			}
			$(function(){
				
				tcolspan("table","1");
			})
		</script>
		<title></title>
		<style type="text/css">
		table{border: 1px solid pink;border-collapse:collapse;}
		tr{border-bottom: 1px solid pink;}
		td{border-right: 1px solid pink;padding: 5px;}
		</style>
	</head>
	<body>
		<table>
			<tr>
				<td>jquery</td>
				<td>jquery</td>
				<td>javascript</td>
				<td>xml</td>
			</tr>
			<tr>
				<td>jquery</td>
				<td>jquery</td>
				<td>javascript</td>
				<td>xml</td>
			</tr>
			<tr>
				<td>jquery1</td>
				<td>jquery</td>
				<td>javascript</td>
				<td>xml</td>
			</tr>
			<tr>
				<td>jquery</td>
				<td>jquery</td>
				<td>javascript</td>
				<td>xml</td>
			</tr>
		</table>
	</body>
</html>

 类似资料: