日期:2014-05-16 浏览次数:20384 次
function MouseDownToResize(obj) {
setTableLayoutToFixed();
obj.mouseDownX = event.clientX; //当事件被触发时鼠标指针相对于浏览器页面(或客户区)的水平坐标
obj.pareneTdW = obj.parentNode.offsetWidth; //获取Td的宽度
obj.pareneTableW = document.getElementById("Grid_DTable1").offsetWidth; //获取整个表格的宽度
obj.setCapture(); //设置属于当前文档的对象的鼠标捕捉
}
function MouseMoveToResize(obj) {
if (!obj.mouseDownX) return false; //
var newWidth = obj.pareneTdW * 1 + event.clientX * 1 - obj.mouseDownX; //鼠标移动时把宽度设置为之前的宽度加上水平位移再减去之前相对于浏览器的坐标
if (newWidth > 10) {
var theObjTable = document.getElementById("Grid_DTable1");
obj.parentElement.style.width = newWidth;
theObjTable.style.width = obj.pareneTdW * 1 + event.clientX * 1 - obj.mouseDownX;
}
}
function MouseUpToResize(obj) {
obj.releaseCapture(); //释放当前文档中对象的鼠标捕捉
obj.mouseDownX = 0;
}
function setTableLayoutToFixed() {
var theObjTable = document.getElementById("Grid_DTable1");
if (theObjTable.style.tableLayout == 'fixed') return;
var headerTr = theObjTable.rows[0];
for (var i = 0; i < headerTr.cells.length; i++) {
headerTr.cells[i].styleOffsetWidth = headerTr.cells[i].offsetWidth;
}
for (var i = 0; i < headerTr.cells.length; i++) {
headerTr.cells[i].style.width = headerTr.cells[i].styleOffsetWidth;
}
theObjTable.style.tableLayout = 'fixed';
}