效果图:拖动带颜色位置上的竖杠,可以左右拖动表格宽度,上下宽度一起改变

 

缺点:拖动点极其精确,想拖动一次要有耐心

 

再帖代码:

<html> 
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style>
.resizeDivClass
{
position:absolute;
background-color:gray;
width:1;
z-index:1;
left:1;
cursor:e-resize; 
} 
.td1 { 
 font-size: 12px;
 white-space:nowrap;
 overflow:hidden;   
 text-overflow:ellipsis;
 color:#0000ff;   
 pos:expression(this.offsetLeft*1+this.offsetWidth*1+tab.offsetLeft); 
} 
</style>
<script language=javascript> 
function MouseDownToResize(obj){  
 obj.mouseDownX=event.clientX;
 obj.pareneTdW=obj.parentElement.offsetWidth;
 obj.pareneTableW=tab.offsetWidth;
 obj.setCapture();
}
function MouseMoveToResize(obj){  
 if(!obj.mouseDownX) return false;
 var newWidth=obj.pareneTdW*1+event.clientX*1-obj.mouseDownX;
 if(newWidth>0)
 {
   obj.parentElement.style.width = newWidth;
   tab.style.width=obj.pareneTableW*1+event.clientX*1-obj.mouseDownX;
   for (var i=1; i<=tab.rows(0).cells.length;i++){
     var obj = eval("mydiv"+i);    
      obj.style.left = obj.parentElement.offsetLeft*1+obj.parentElement.offsetWidth*1+tab.offsetLeft;//obj.parentElement.style.pos;
   }
 }
}
function MouseUpToResize(obj){
  obj.releaseCapture();
  obj.mouseDownX=0;
} 

function init(){  
  var tempStr = "";
  for (var i=1; i<=tab.rows(0).cells.length;i++){
    tempStr = '<div id="mydiv'+i+'" class="resizeDivClass" οnmοusedοwn="MouseDownToResize(this);" οnmοusemοve="MouseMoveToResize(this);" οnmοuseup="MouseUpToResize(this);"></div>';      
    tab.rows(0).cells(i-1).innerHTML = tab.rows(0).cells(i-1).innerHTML+tempStr;     
    var obj = eval("mydiv"+i);    
    obj.style.left = obj.parentElement.style.pos;    
  }
  
}
</script> 
</head> 
<body οnlοad="init()">
<table id=tab STYLE="table-layout:fixed;" >
<tr bgcolor=cccccc >
<td valign=top class="td1" ><nobr>改变table的列宽度改</nobr></td>
<td valign=top class="td1" ><nobr>改变table的列宽度改</nobr></td>
<td valign=top class="td1" ><nobr>改变table的列宽度改</nobr></td>
</tr> 

<tr>
<td class="td1"><nobr>改变table的列宽度</nobr></td>
<td class="td1"><nobr>改变table的列宽度</nobr></td>
<td class="td1"><nobr>改变table的列宽度</nobr></td>
</tr>
</table>
</body>
</html>

 

 

黑色头发  http://heisetoufa.iteye.com