<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>鍚堝苟琛ㄦ牸</title>
<script>
///////////////////////////////////////////////
// 鍔熻兘錛氬悎騫惰〃鏍?
// 鍙傛暟錛歵b錛嶏紞闇€瑕佸悎騫剁殑琛ㄦ牸ID
// 鍙傛暟錛歝olLength錛嶏紞闇€瑕佸鍓嶅嚑鍒楄繘琛屽悎騫訛紝姣斿錛?
// 鎯衝悎騫跺墠涓ゅ垪錛屽悗闈㈢殑鏁版嵁鍒楀拷鐣ュ悎騫訛紝colLength搴斾負2
// 緙虹渷琛ㄧず瀵瑰叏閮ㄥ垪鍚堝苟
// data: 2005.11.6
///////////////////////////////////////////////
function uniteTable(tb,objCol){
// 嬀€鏌ヨ〃鏍兼槸鍚﹁鏁?
if (!checkTable(tb)) return;
var i=0;
var j=0;
var rowCount=tb.rows.length; // 琛屾暟
var colCount=tb.rows[0].cells.length; // 鍒楁暟
var obj1=null;
var obj2=null;
// 涓烘瘡涓崟鍏冩牸鍛藉悕
for (i=0;i<rowCount;i++){
for (j=0;j<colCount;j++){
tb.rows[i].cells[j].id="tb__" + i.toString() + "_" + j.toString();
}
}
// 閫愬垪嬀€鏌ュ悎騫?
for (t=0;t<objCol.length;t++)
{
i=objCol[t];
obj1=document.getElementById("tb__0_"+i.toString())
for (j=1;j<rowCount;j++)
{
obj2=document.getElementById("tb__"+j.toString()+"_"+i.toString());
if (obj1.innerHTML == obj2.innerHTML)//淇敼浜嗗師鏉ョ殑innerText
{
obj1.rowSpan++;
obj2.parentNode.removeChild(obj2);
}
else
{
obj1=document.getElementById("tb__"+j.toString()+"_"+i.toString());
}
}
}
}
/////////////////////////////////////////
// 鍔熻兘錛氭鏌ヨ〃鏍兼槸鍚﹁鏁?
// 鍙傛暟錛歵b錛嶏紞闇€瑕佹鏌ョ殑琛ㄦ牸ID
// data: 2005.11.6
/////////////////////////////////////////
function checkTable(tb){
if (tb.rows.length==0) return false;
if (tb.rows[0].cells.length==0) return false;
for (var i=0;i<tb.rows.length;i++){
if (tb.rows[0].cells.length != tb.rows[i].cells.length) return false;
}
return true;
}
</script>
</head>
<body>
<table width="400" border="1" id="table1">
<tr>
<td>a</td>
<td>for</td>
<td>100</td>
<td>200</td>
</tr>
<tr>
<td>a</td>
<td>for</td>
<td>150</td>
<td>230</td>
</tr>
<tr>
<td>a</td>
<td>if</td>
<td>150</td>
<td>200</td>
</tr>
<tr>
<td>a</td>
<td>if</td>
<td>300</td>
<td>240</td>
</tr>
<tr>
<td>a</td>
<td>if</td>
<td>320</td>
<td>240</td>
</tr>
</table>
<br>
<input type="button" value="鍚堝苟琛ㄦ牸" onClick="uniteTable(table1,Array(0,1,3))">
</body> html