代碼如下,可直接運行:
復制代碼 代碼如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<SCRIPT LANGUAGE="JavaScript">
function autoRowSpan(tb,row,col)
{
var lastValue="";
var value="";
var pos=1;
for(var i=row;i<tb.rows.length;i++){
value = tb.rows[i].cells[col].innerText;
if(lastValue == value){
tb.rows[i].deleteCell(col);
tb.rows[i-pos].cells[col].rowSpan = tb.rows[i-pos].cells[col].rowSpan+1;
pos++;
}else{
lastValue = value;
pos=1;
}
}
}
</SCRIPT>
<BODY onload="autoRowSpan(tb,0,0)">
<TABLE id="tb" border="1">
<THEAD>
<TR >
<TD>國家</TD>
<TD>地區</TD>
</TR>
</THEAD>
<TR>
<TD>中國</TD>
<TD>河南</TD>
</TR>
<TR>
<TD>中國</TD>
<TD>四川</TD>
</TR>
<TR>
<TD>中國</TD>
<TD>北京</TD>
</TR>
<TR>
<TD>美國</TD>
<TD>紐約</TD>
</TR>
<TR>
<TD>美國</TD>
<TD>洛杉矶</TD>
</TR>
<TR>
<TD>英國</TD>
<TD>倫敦</TD>
</TR>
</TABLE>
</BODY>
</HTML>