这是动态生成的单元格,合并是向右合并的,我要使他向左该怎样合并!请各位哥哥、姐姐帮忙看一下哈!
<%@ page contentType="text/html; charset=gb2312"%> 
<html> 
<head> 
<title>--表格--</title> 
</head>
<body> 
<script> 
var i,j,tmp,l,r;
var hand1=0;
var hand2=0;
 function a(value)
  {
    hand1=value;
  }
 function b(value)
  {
    hand2=value;
  } 
//创建表格
function createtable() 

tmp="<table border=1 width=5% id =tb1>" 
 l=document.all.txt1.value==''?0:document.all.txt1.value; //获取文本框的值,这里我想用if-else但太麻烦
 document.all.txt1.value=l;
 r=document.all.txt2.value==''?0:document.all.txt2.value; 
 document.all.txt2.value=r;     if(isNaN(l))
        {  
        if(isNaN(r))
          {
           alert("输入非法字符,请重新输入!");
           document.all.txt1.focus();
           return false;
          }else{
             alert("输入非法字符,请重新输入!");
             document.all.txt1.focus();
             return false;
            }
        }
     if(l==0 || r== 0)
      {
         alert("无输入,请重新输入!");
         document.all.txt1.focus();
         return false;
       }
for(j=0;j<l;j++) 

tmp=tmp+"<tr>" 
for(i=0;i<r;i++) 
 { 
       if((hand1==0)&&(hand2==0))
            {
               tmp=tmp+"<td style='background: #7B7B7B;'>" 
               tmp=tmp+"UESTC" 
               tmp=tmp+"</td>"     
             }
        if((hand1==1)&&(hand2==0))
          {
             if(i%2==0)
               {
                  tmp=tmp+"<td style='background: #F9F900;'>"// 行显示黄色
                  tmp=tmp+"UESTC" 
                  tmp=tmp+"</td>" 
                }
            else
               {   
 tmp=tmp+"<td style='background: #7B7B7B;'>" 
                 tmp=tmp+"UESTC" 
                 tmp=tmp+"</td>" 
                 }
            }
        if((hand1==0)&&(hand2==1))
             {
               if(j%2==0)
                 {
                    tmp=tmp+"<td style='background: #F9F900;'>" //列显示黄色 
                    tmp=tmp+"UESTC" 
                    tmp=tmp+"</td>" 
                  }
               else
                  {   
    tmp=tmp+"<td style='background: #7B7B7B;'>" 
                    tmp=tmp+"UESTC" 
                    tmp=tmp+"</td>" 
                   }
              }
        if((hand1==1)&&(hand2==1))
              {
                if(j%2==0&&i%2==0)        
                 {
                    tmp=tmp+"<td style='background: #7B7B7B;'>" 
                    tmp=tmp+"UESTC" 
                    tmp=tmp+"</td>"
                  }
              else
                  { 
                   if(j%2==0||i%2==0)
                     {
                       tmp=tmp+"<td style='background: #F9F900;'>" 
                       tmp=tmp+"UESTC" 
                       tmp=tmp+"</td>" 
                       }
                    else
                       {
       tmp=tmp+"<td style='background: #7B7B7B;'>" 
                       tmp=tmp+"UESTC" 
                       tmp=tmp+"</td>" 
                       }
                    }
              }   
       

tmp=tmp+"</tr>" 

tmp=tmp+"</table>" 
aa.innerHTML=tmp //aa表示form的NAME
 
}//合并单元格
function changetable(){
createtable();
 var tab = document.all.tb1;//tb1表示表的id
 if(tab){
l=document.all.txt3.value==''?0:document.all.txt3.value; 
r=document.all.txt4.value==''?0:document.all.txt4.value; 
row=document.all.txt5.value==''?0:document.all.txt5.value; 
col=document.all.txt6.value==''?0:document.all.txt6.value; 
  if(l==0 || r==0 || row==0 || col==0)
    {
      alert("没输入值,请重新输入!");
      document.all.txt3.focus();
      return false;
        }
   var obj = document.all.tb1.childNodes(0).childNodes(l-1).childNodes(r-1);
   if(eval(l+"+"+row+"-"+"1")>document.all.tb1.childNodes(0).childNodes.length)
        {
           alert("不能合并!");
            return false;
          } 
   if(eval(r+"+"+col+"-"+"1")>document.all.tb1.childNodes(0).childNodes.length)
        {
            alert("不能合并!");
            return false;
          }
  var tbody = document.all.tb1.childNodes(0);
   for (var m =0 ; m <eval(col+"-"+"1"); m++)
    {
      tbody.childNodes(l-1).childNodes(r-1).nextSibling.removeNode();
      tbody.childNodes(l-1).childNodes(r-1).nextSibling.removeNode();
     }
  for (var m =0 ; m <eval(row+"-"+"1") ; m++)
    {
     for (var n = 0; n<col; n++ )
      {
        indexRow = eval(m+"+"+l);
        indexCol = eval(n+"+"+r+"-"+"1");
        tbody.childNodes(indexRow).childNodes(eval(r+"-"+"1")).removeNode();
        tbody.childNodes(indexRow).childNodes(eval(r+"-"+"1")).removeNode();
       }
    }
  with(obj)
    {
     colSpan = col;
     rowSpan = row;
    }
  }
   else{
      alert("没有表格!");
      document.all.txt1.focus();
      }
}
</script> 
<div id="aa"></div> 
<h3>请输入要输入的表格的列数和行数:</h3> 
行:&nbsp;<input type=text name="txt1"> 
<br> 
列:&nbsp;<input type=text name="txt2"><br>
<input type="button" value="提交" onclick="createtable()"> 
  <br>
  是否隔列显示:
  <tr><input  type="radio"   name="radio2" value="1" onclick="a(1);";> 是 <input  type="radio"  name="radio2" value="0" onclick="a(0);">否  
   <br>
  是否隔行显示:
  <tr><input  type="radio"   name="radio2" value="1" onclick="b(1);";> 是 <input  type="radio"  name="radio2" value="0" onclick="b(0);">否 
<h3>请输入两个数字</h3> 
<h3>合并单元格: </h3> 
从&nbsp;&nbsp;<input type=text name="txt3">行<input type=text name="txt4">列开始 
<br> 
合并<input type=text name="txt5">行<input type=text name="txt6">列
<br> 
<input type="button" value="合并" onclick="changetable()"> 
</body> 
</html>