JS実装は、列幅を変更することができるテーブルの例を示します.

3116 ワード

 
  




table

























2000001 1997-3-131997-3-131WZJ 1965-3-13 171
2000045 2001-2-152001-3-150WY 1978-8-5 162
2000046 2001-2-232001-3-230LQ 2001-2-23 171

<br>var tTD; // Table Cell, <br>var table = document.getElementById("tb_1"); <br>for (j = 0; j < table.rows[0].cells.length; j++) { <br>table.rows[0].cells[j].onmousedown = function () { <br>// <br>tTD = this; <br>if (event.offsetX > tTD.offsetWidth - 10) { <br>tTD.mouseDown = true; <br>tTD.oldX = event.x; <br>tTD.oldWidth = tTD.offsetWidth; <br>} <br>// Table <br>//table = tTD; while (table.tagName != ‘TABLE') table = table.parentElement; <br>//tTD.tableWidth = table.offsetWidth; <br>}; <br>table.rows[0].cells[j].onmouseup = function () { <br>// <br>if (tTD == undefined) tTD = this; <br>tTD.mouseDown = false; <br>tTD.style.cursor = 'default'; <br>}; <br>table.rows[0].cells[j].onmousemove = function () { <br>// <br>if (event.offsetX > this.offsetWidth - 10) <br>this.style.cursor = 'col-resize'; <br>else <br>this.style.cursor = 'default'; <br>// Table Cell <br>if (tTD == undefined) tTD = this; <br>// <br>if (tTD.mouseDown != null && tTD.mouseDown == true) { <br>tTD.style.cursor = 'default'; <br>if (tTD.oldWidth + (event.x - tTD.oldX)>0) <br>tTD.width = tTD.oldWidth + (event.x - tTD.oldX); <br>// <br>tTD.style.width = tTD.width; <br>tTD.style.cursor = 'col-resize'; <br>// Cell <br>table = tTD; while (table.tagName != 'TABLE') table = table.parentElement; <br>for (j = 0; j < table.rows.length; j++) { <br>table.rows[j].cells[tTD.cellIndex].width = tTD.width; <br>} <br>// <br>//table.width = tTD.tableWidth + (tTD.offsetWidth �C tTD.oldWidth); <br>//table.style.width = table.width; <br>} <br>}; <br>} <br>