要记得加上px单位,以后设计left,top这种的属性,都要记得加px单位 function MouseMoveToResize(event) {
if (!currentResizeTdObj) return;
var obj = currentResizeTdObj;
event = event || window.event;
if (!obj.mouseDownX) return false;
if (obj.parentNode.rowIndex == 0) {
var newWidth = obj.tdW * 1 + event.clientX * 1 - obj.mouseDownX;
if (newWidth > 0) obj.style.width = newWidth+'px';
else obj.style.width = 1;
}
if (obj.cellIndex == 0) {
var newHeight = obj.tdH * 1 + event.clientY * 1 - obj.mouseDownY;
if (newHeight > 0) obj.style.height = newHeight + 'px';
else obj.style.height = 1;
}
}
function MouseUpToResize() {
if (!currentResizeTdObj) return;
if (currentResizeTdObj.releaseCapture) currentResizeTdObj.releaseCapture();
currentResizeTdObj = null;
}
//改变表格行列宽函数
function ResizeTable_Init(table, needChangeWidth, needChangeHeight) {
if (!needChangeWidth && !needChangeHeight)
return;
var oTh = table.rows[0];
if (needChangeWidth) {
for (var i = 0; i < oTh.cells.length; i++) {
var cell = oTh.cells[i];
cell.style.cursor = "e-resize";
cell.style.width = cell.offsetWidth + 'px';
cell.onmousedown = MouseDownToResize;
}
}
if (needChangeHeight) {
for (var j = 0; j < table.rows.length; j++) {
var cell = table.rows[j].cells[0];
cell.style.cursor = "s-resize";
cell.onmousedown = MouseDownToResize;
}
}
if (needChangeWidth && needChangeHeight)
oTh.cells[0].style.cursor = "se-resize";
table.style.width = null;
table.style.tableLayout = "fixed";
}
if (!currentResizeTdObj) return;
var obj = currentResizeTdObj;
event = event || window.event;
if (!obj.mouseDownX) return false;
if (obj.parentNode.rowIndex == 0) {
var newWidth = obj.tdW * 1 + event.clientX * 1 - obj.mouseDownX;
if (newWidth > 0) obj.style.width = newWidth+'px';
else obj.style.width = 1;
}
if (obj.cellIndex == 0) {
var newHeight = obj.tdH * 1 + event.clientY * 1 - obj.mouseDownY;
if (newHeight > 0) obj.style.height = newHeight + 'px';
else obj.style.height = 1;
}
}
function MouseUpToResize() {
if (!currentResizeTdObj) return;
if (currentResizeTdObj.releaseCapture) currentResizeTdObj.releaseCapture();
currentResizeTdObj = null;
}
//改变表格行列宽函数
function ResizeTable_Init(table, needChangeWidth, needChangeHeight) {
if (!needChangeWidth && !needChangeHeight)
return;
var oTh = table.rows[0];
if (needChangeWidth) {
for (var i = 0; i < oTh.cells.length; i++) {
var cell = oTh.cells[i];
cell.style.cursor = "e-resize";
cell.style.width = cell.offsetWidth + 'px';
cell.onmousedown = MouseDownToResize;
}
}
if (needChangeHeight) {
for (var j = 0; j < table.rows.length; j++) {
var cell = table.rows[j].cells[0];
cell.style.cursor = "s-resize";
cell.onmousedown = MouseDownToResize;
}
}
if (needChangeWidth && needChangeHeight)
oTh.cells[0].style.cursor = "se-resize";
table.style.width = null;
table.style.tableLayout = "fixed";
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货