最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

JS實現(xiàn)可改變列寬的table實例

 更新時間:2013年07月02日 16:51:10   作者:  
本文為大家詳細(xì)介紹下通過JS實現(xiàn)可改變列寬的table,具體的思路及代碼如下,感興趣的朋友可以參考下哈,希望對大家有所幫助
復(fù)制代碼 代碼如下:

<!DOCTYPE HTML>
<html>
<head>
<meta charset="gbk">
<title>table</title>
</head>
<body>
<table id="tb_1" cellspacing="0" cellpadding="2" width="100%" border="1">
<tbody>
<tr align="center" bgcolor="#dcdcdc">
<td style="width:100px;">用戶編號</td>
<td>試用時間</td><td>轉(zhuǎn)正時間</td><td>性別</td><td>姓名拼音</td>
<td>生日時間</td><td>民族</td><td>身高</td>
</tr>
<tr>
<td>2000001</td>
<td>1997-3-13</td><td>1997-3-13</td><td>1</td><td>WZJ</td>
<td>1965-3-13</td><td>漢</td><td>171</td>
</tr>
<tr>
<td>2000045</td>
<td>2001-2-15</td><td>2001-3-15</td><td>0</td><td>WY</td>
<td>1978-8-5</td><td>漢</td><td>162</td>
</tr>
<tr>
<td>2000046</td>
<td>2001-2-23</td><td>2001-3-23</td><td>0</td><td>LQ</td>
<td>2001-2-23</td><td>漢</td><td>171</td>
</tr>
</tbody>
</table>
<script type="text/javascript">
var tTD; //用來存儲當(dāng)前更改寬度的Table Cell,避免快速移動鼠標(biāo)的問題
var table = document.getElementById("tb_1");
for (j = 0; j < table.rows[0].cells.length; j++) {
table.rows[0].cells[j].onmousedown = function () {
//記錄單元格
tTD = this;
if (event.offsetX > tTD.offsetWidth - 10) {
tTD.mouseDown = true;
tTD.oldX = event.x;
tTD.oldWidth = tTD.offsetWidth;
}
//記錄Table寬度
//table = tTD; while (table.tagName != ‘TABLE') table = table.parentElement;
//tTD.tableWidth = table.offsetWidth;
};
table.rows[0].cells[j].onmouseup = function () {
//結(jié)束寬度調(diào)整
if (tTD == undefined) tTD = this;
tTD.mouseDown = false;
tTD.style.cursor = 'default';
};
table.rows[0].cells[j].onmousemove = function () {
//更改鼠標(biāo)樣式
if (event.offsetX > this.offsetWidth - 10)
this.style.cursor = 'col-resize';
else
this.style.cursor = 'default';
//取出暫存的Table Cell
if (tTD == undefined) tTD = this;
//調(diào)整寬度
if (tTD.mouseDown != null && tTD.mouseDown == true) {
tTD.style.cursor = 'default';
if (tTD.oldWidth + (event.x - tTD.oldX)>0)
tTD.width = tTD.oldWidth + (event.x - tTD.oldX);
//調(diào)整列寬
tTD.style.width = tTD.width;
tTD.style.cursor = 'col-resize';
//調(diào)整該列中的每個Cell
table = tTD; while (table.tagName != 'TABLE') table = table.parentElement;
for (j = 0; j < table.rows.length; j++) {
table.rows[j].cells[tTD.cellIndex].width = tTD.width;
}
//調(diào)整整個表
//table.width = tTD.tableWidth + (tTD.offsetWidth – tTD.oldWidth);
//table.style.width = table.width;
}
};
}
</script>
</body>
</html>

相關(guān)文章

最新評論

新宁县| 万安县| 平乡县| 永清县| 顺义区| 隆昌县| 高碑店市| 定襄县| 东方市| 施甸县| 东丽区| 同江市| 株洲县| 平乐县| 西充县| 芦山县| 西林县| 华阴市| 霍林郭勒市| 西贡区| 芮城县| 和平区| 伽师县| 巴塘县| 玉溪市| 丽水市| 嵊州市| 玉龙| 县级市| 遂溪县| 永吉县| 安多县| 古田县| 洛隆县| 嘉兴市| 日喀则市| 桐梓县| 大连市| 延川县| 黄山市| 汉中市|