我这里有一个例子(摘自以前的帖子):
<HTML>
<HEAD>
<META content="text/html; charset=gb2312" http-equiv=Content-Type>
<STYLE type=text/css>BODY {
BACKGROUND: white; COLOR: black; FONT-FAMILY: verdana,arial,helvetica; FONT-SIZE: 12px
}
.tableData {
BACKGROUND: white; BORDER-BOTTOM: white 1px dashed; BORDER-LEFT: white 1px dashed; BORDER-RIGHT: white 1px dashed; BORDER-TOP: white 1px dashed; COLOR: black; CURSOR: hand; FONT-FAMILY: verdana,arial,helvetica; FONT-SIZE: 12px
}
.tableDataSel {
BACKGROUND: #6090d0; BORDER-BOTTOM: #6090d0 1px dashed; BORDER-LEFT: #6090d0 1px dashed; BORDER-RIGHT: #6090d0 1px dashed; BORDER-TOP: #6090d0 1px dashed; COLOR: white; CURSOR: hand; FONT-FAMILY: verdana,arial,helvetica; FONT-SIZE: 12px
}
.tableDataHit {
BACKGROUND: #d0e0ff; BORDER-BOTTOM: #d0e0ff 1px dashed; BORDER-LEFT: #d0e0ff 1px dashed; BORDER-RIGHT: #d0e0ff 1px dashed; BORDER-TOP: #d0e0ff 1px dashed; COLOR: black; CURSOR: hand; FONT-FAMILY: verdana,arial,helvetica; FONT-SIZE: 12px
}
.tableDataOver {
BACKGROUND: #d0e0ff; BORDER-BOTTOM: #d0e0ff 1px dashed; BORDER-LEFT: #d0e0ff 1px dashed; BORDER-RIGHT: #d0e0ff 1px dashed; BORDER-TOP: #d0e0ff 1px dashed; COLOR: black; CURSOR: hand; FONT-FAMILY: verdana,arial,helvetica; FONT-SIZE: 12px
}
.controlPanel {
BACKGROUND: silver; COLOR: black; CURSOR: hand; FONT-FAMILY: verdana,arial,helvetica; FONT-SIZE: 14px
}
.controlPanelMouseOver {
BACKGROUND: #d0e0ff; COLOR: black; CURSOR: hand; FONT-FAMILY: verdana,arial,helvetica; FONT-SIZE: 14px
}
.delMouseOver {
BACKGROUND: #d0e0ff; COLOR: black; CURSOR: hand; FONT-FAMILY: verdana,arial,helvetica; FONT-SIZE: 14px
}
.scheduleButtonVisible {
BACKGROUND: silver; BORDER-BOTTOM: gray 1px dashed; BORDER-LEFT: white 1px dashed; BORDER-RIGHT: gray 1px dashed; BORDER-TOP: white 1px dashed; COLOR: black; CURSOR: hand; FONT-FAMILY: webdings; FONT-SIZE: 12px
}
</STYLE>
<SCRIPT language=javascript>
var modified=0
var currentLine=-1
var line=-1
function lightOn(ln)
{
if (ln==null)
  ln=parseInt(event.srcElement.ln,10)
for (i=1;i<PLList.rows.length;i++)
  if (tdt[i].ln==ln)
   line=i
cln=currentLine
oldLine=-1
for (i=1;i<PLList.rows.length;i++)
  if (tdt[i].ln==cln)
   oldLine=i
if (line==oldLine)
  return
//if td <0 then only clear all title
if (line>0)
{
  document.all.tdt[line].className="tableDataHit";
  document.ecform("medication")[line].className="tableDataHit";
  if (oldLine>0)
  {
   document.all.tdt[oldLine].className="tableData";
   document.ecform("medication")[oldLine].className="tableData";
  }
  currentLine=ln
}
}function move(direc){
//向下移动direc行,并将移动到的行高亮度显示 if(line+direc<1 || (line+direc)>document.all.tdt.length-1) return;
var temp=document.ecform.medication[line].value;
document.ecform.medication[line].value=document.ecform.medication[line+direc].value;
document.ecform.medication[line+direc].value=temp

line+=direc;
lightOn(line);
}
function delIt()
{
line=parseInt(event.srcElement.ln,10)
  
if (line>0)
  for (i=1;i<PLList.rows.length;i++)
   if (tdt[i].ln==line)
   {
    if ( document.ecform.medication[i].value.length>0 )
     if (!confirm("Are you sure you want to delete this record?"))
      return
    PLList.deleteRow(i)
   }
}
function modifiedIt(field)
{
// field.value=checkText(field.value);
modified=1
line=parseInt(event.srcElement.ln,10)
  
if (line>0)
   for (i=1;i<PLList.rows.length;i++)
    if (tdt[i].ln==line)
     document.ecform.edit[i].value=1
}
function newHospitalVisit()
{
newRow=PLList.insertRow(PLList.rows.length);
newRow.id="tdt";
newRow.ln=allCount;
newRow.bgColor="#e0e0e0";
newRow.className="tableData";
newRow.onclick=lightOn;c1=newRow.insertCell(0);
c1.id="delItem";
c1.ln=allCount;
c1.className="scheduleButtonVisible";
c1.onclick=delIt;
c1.onmouseover=mouseOver;
  c1.onmouseout=mouseOut;
c1.innerHTML="<input type=hidden name=PLID value=0><input type='hidden' name='edit' value=0>";
c2=newRow.insertCell(1);
c2.ln=allCount;
c2.innerHTML="<input type=text size=58 maxlength=100 name=medication ln="+allCount+" class=tableData onkeyup='modifiedIt()'>"
allCount++
}
function mouseOver()
{
event.srcElement.className="delMouseOver"
}
function mouseOut()
{
event.srcElement.className="scheduleButtonVisible"
}
</SCRIPT>
  <META content="Microsoft FrontPage 4.0" name=GENERATOR>
</HEAD>
<BODY bgColor=white>
<FORM method=post name=ecform>
  <DIV id=div1 
style="LEFT: 0px; POSITION: absolute; TOP: 0px; VISIBILITY: visible; WIDTH: 658px"> 
    <TABLE bgColor=silver border=2 borderColorDark=gray borderColorLight=silver 
cellPadding=2 cellSpacing=1 cols=1 id=PLList rules=rows width="100%">
      <TBODY> 
      <TR bgColor=#0a6846 id=tdt> 
        <TH width=80><FONT color=white>删除 
          <INPUT name=PLID type=hidden>
          <INPUT 
      name=edit type=hidden>
          </FONT></TH>
        <TH width="559"> 
          <INPUT name=medication type=hidden>
          <FONT 
      color=white>变化表格 </font> 
      </TR>
      <TR bgColor=#e0e0e0 class=tableData id=tdt onclick=lightOn() ln="1"> 
        <TD class=scheduleButtonVisible onclick=delIt() onmouseout=mouseOut() 
    onmouseover=mouseOver() ln="1" width="80"><FONT size=2> 
          <INPUT name=PLID type=hidden 
      value=54 ln="1">
          <INPUT name=edit type=hidden value=0>
          </FONT></TD>
        <TD ln="1" width="559"> 
          <INPUT class=tableData maxLength=100 name=medication 
      onkeyup=modifiedIt(this) size=58 value="like it?" ln="1">
        </TD>
      </TR>
      <TR bgColor=#e0e0e0 class=tableData id=tdt onclick=lightOn() ln="2"> 
        <TD class=scheduleButtonVisible onclick=delIt() onmouseout=mouseOut() 
    onmouseover=mouseOver() ln="2" width="80"><FONT size=2> 
          <INPUT name=PLID type=hidden 
      value=55 ln="2">
          <INPUT name=edit type=hidden value=0>
          </FONT></TD>
        <TD ln="2" width="559"> 
          <INPUT class=tableData maxLength=100 name=medication 
      onkeyup=modifiedIt(this) size=58 value="how about it?" ln="2">
        </TD>
      </TR>
      <TR bgColor=#e0e0e0 class=tableData id=tdt onclick=lightOn() ln="3"> 
        <TD class=scheduleButtonVisible onclick=delIt() onmouseout=mouseOut() 
    onmouseover=mouseOver() ln="3" width="80"><FONT size=2> 
          <INPUT name=PLID type=hidden 
      value=56 ln="3">
          <INPUT name=edit type=hidden value=0>
          </FONT></TD>
        <TD ln="3" width="559"> 
          <INPUT class=tableData maxLength=100 name=medication 
      onkeyup=modifiedIt(this) size=58 ln="3">
        </TD>
      </TR>
      </TBODY> 
    </TABLE>
    <SCRIPT>
allCount=4
</SCRIPT>
    

    <TABLE align=center border=1 borderColorDark=white borderColorLight=gray 
cellPadding=1 cellSpacing=1 class=controlPanel cols=4 rules=all width="100%" 
nowrap>
      <TBODY> 
      <TR> 
        <TD align=middle class=controlPanel onclick=newHospitalVisit() 
    onmouseout="this.className='controlPanel'" 
    onmouseover="this.className='controlPanelMouseOver'"><font size="2" face="仿宋_GB2312, 楷体_GB2312">添加一行</font></TD>
      </TR>
      <TR> 
        <TD align=middle class=controlPanel onclick=move(-1) 
    onmouseout="this.className='controlPanel'" 
    onmouseover="this.className='controlPanelMouseOver'"><font size="2" face="仿宋_GB2312, 楷体_GB2312">向上移动</font></TD>
      </TR>
      <TR> 
        <TD align=middle class=controlPanel onclick=move(1) 
    onmouseout="this.className='controlPanel'" 
    onmouseover="this.className='controlPanelMouseOver'"><font size="2" face="仿宋_GB2312, 楷体_GB2312">向下移动</font></TD>
      </TR>
      </TBODY> 
    </TABLE>
  </DIV>
</FORM>
</BODY>
</HTML>

解决方案 »

  1.   

    这个是weidegong的作品,不错不错。
      

  2.   

    <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>
      

  3.   

    to: seabell(百合心)     你的这个很不错,我先看看怎么做的,不懂得地方还要麻烦你
      

  4.   

    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;
    // 加点注释
    htmlstr=htmlstr.substr(4);  //substr这个是做什么用的?大致讲一下doTab吧
      

  5.   

    楼主:实在抱歉我今天赶任务,一直没来
    substr(4)是网景在substring()方法上的变更,第一个参数指开始的序号(和substring同),后一个参数指取串的长度,如省略则一直取到串尾这个例子也是我以前存的,我还得看看再答复你
      

  6.   

    thinkover(至真宝) 
    你的方法挺方便的