效果圖:拖動紅色的豎槓,可以左右拖動表格寬度,上下寬度一起改變
特點:拖動容易,aaa列的文字拖動後不會被覆蓋,ddd列的文字會被表格線 覆蓋
代碼:
Html代碼
<style>
.resizeDivClass
{
position:relative;
background-color:red;
width:2;
z-index:1;
left:expression(this.parentElement.offsetWidth-1);
cursor:e-resize;
}
</style>
<script language=javascript>
function MouseDownToResize(obj){
obj.mouseDownX=event.clientX;
objobj.pareneTdW=obj.parentElement.offsetWidth;
obj.pareneTableW=theObjTable.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;
theObjTable.style.width=obj.pareneTableW*1+event.clientX*1- obj.mouseDownX;
}
}
function MouseUpToResize(obj){
obj.releaseCapture();
obj.mouseDownX=0;
}
</script>
</head>
<body>
改變table的列寬度
<table id=theObjTable STYLE="table-layout:fixed" >
<tr bgcolor=cccccc >
<td valign=top >
<font class="resizeDivClass" onmousedown="MouseDownToResize (this);" onmousemove="MouseMoveToResize(this);" onmouseup="MouseUpToResize(this);"></font>
aaa</td>
<td valign=top >
<font class="resizeDivClass" onmousedown="MouseDownToResize (this);" onmousemove="MouseMoveToResize(this);" onmouseup="MouseUpToResize(this);"></font>
ddd</td>
<td valign=top >
<font class="resizeDivClass" onmousedown="MouseDownToResize (this);" onmousemove="MouseMoveToResize(this);" onmouseup="MouseUpToResize(this);"></font>
ddd</td>
</tr>
<tr>
<td>快樂不是因為擁有的多,而是計較的少。 </td><td>bbbb</td><td>dddd</td>
</tr>
</table>
</body>
</html>