HTML DOM tableLayout 屬性
定義和用法
tableLayout 屬性用來顯示表格單元格、行、列的算法規(guī)則。
固定表格布局:
固定表格布局與自動(dòng)表格布局相比,允許瀏覽器更快地對表格進(jìn)行布局。
在固定表格布局中,水平布局僅取決于表格寬度、列寬度、表格邊框?qū)挾、單元格間距,而與單元格的內(nèi)容無關(guān)。
通過使用固定表格布局,用戶代理在接收到第一行后就可以顯示表格。
自動(dòng)表格布局:
在自動(dòng)表格布局中,列的寬度是由列單元格中沒有折行的最寬的內(nèi)容設(shè)定的。
此算法有時(shí)會較慢,這是由于它需要在確定最終的布局之前訪問表格中所有的內(nèi)容。
語法:
Object.style.tableLayout=automatic|fixed
可能的值
值 | 描述 |
---|---|
automatic | 默認(rèn)。列寬度由單元格內(nèi)容設(shè)定。 |
fixed | 列寬由表格寬度和列寬度設(shè)定。 |
實(shí)例
本例設(shè)置固定表格布局:
<html>
<head>
<script type="text/javascript">
function setFixedTableLayout()
{
document.getElementById('myTable').style.tableLayout="fixed";
}
</script>
</head>
<body>
<table id="myTable" border="1" width="100%">
<col width="20%"><col width="40%"><col width="40%">
<tr>
<td>1000000000000000000000000000</td>
<td>10000000</td>
<td>100</td>
</tr>
</table>
<input type="button" onclick="setFixedTableLayout()"
value="Set fixed table layout">
</body>
</html>