百合心的代码:<table border="1" width="100%" id=tab1 onmousedown=tabStart() onmouseup=tabEnd()>
  <tr>
    <td width="25%">111</td>
    <td width="25%">111</td>
    <td width="25%"> </td>
    <td width="25%"> </td>
  </tr>
  <tr>
    <td width="25%">222</td>
    <td width="25%"> </td>
    <td width="25%"> </td>
    <td width="25%"> </td>
  </tr>
  <tr>
    <td width="25%"> </td>
    <td width="25%"> </td>
    <td width="25%"> </td>
    <td width="25%"> </td>
  </tr>
</table>
<p>从第<input type="text" name="col1" size="4">列到第<input type="text" name="col2" size="4">列&nbsp;&nbsp;&nbsp;   
从第<input type="text" name="row1" size="4">行到第<input type="text" name="row2" size="4">行<input type="button" value="合并" onclick=doTab()></p>  
<script>  
function doTab(){  
x1=col1.value-1;  
x2=col2.value-1;  
y1=row1.value-1;  
y2=row2.value-1;  
if (x1==x2 && y1==y2) return;  
htmlstr="";  
xspan=0;
yspan=0;
for (i=x1;i<=x2;i++) xspan+=tab1.rows[y1].cells[i].colSpan;
for (i=y1;i<=y2;i++) yspan+=tab1.rows[i].cells[x1].rowSpan;

for (i=y1;i<=y2;i++) { 
htmlstr+="<br>"; 
 
for(j=x1;j<=x2;j++){  
htmlstr+=tab1.rows[i].cells[j].innerHTML;  

}

htmlstr=htmlstr.substr(4); 
for (i=y1;i<=y2;i++){ 
j=x1; 
while (j<x2){ 
    tab1.rows[i].deleteCell(x1); 
    j++; 

    tab1.rows[i].cells[x1].colSpan=xspan;
}
for (i=y2;i>y1;i--){
tab1.rows[i].deleteCell(x1);
}
tab1.rows[y1].cells[x1].rowSpan=yspan;
tab1.rows[y1].cells[x1].innerHTML=htmlstr; 
//alert(htmlstr);  
}  
function tabStart(){  
    obj=window.event.srcElement;  
    col1.value=obj.cellIndex+1;  
    col2.value=col1.value;  
    row1.value=obj.parentElement.rowIndex+1;  
    row2.value=row1.value;  
}  
function tabEnd(){  
    obj=window.event.srcElement;  
    col2.value=obj.cellIndex+1;  
    row2.value=obj.parentElement.rowIndex+1;  
}  
</script>