td/th colSpan 屬性
td/th 對(duì)象定義和用法
colSpan 屬性可設(shè)置或返回表元橫跨的列數(shù)。
語(yǔ)法
設(shè)置 colSpan 屬性:
tdObject.colSpan="number"
或者
thObject.colSpan="number"
或者
thObject.colSpan="number"
返回 colSpan 屬性:
tdObject.colSpan
或者
thObject.colSpan
或者
thObject.colSpan
Tip: There is no default value for the colSpan property.
值 | 描述 |
---|---|
number | 定義橫跨的列數(shù) |
瀏覽器支持
所有主要瀏覽器都支持 colSpan 屬性
實(shí)例
實(shí)例
下面的例子更改了表元橫跨的列數(shù):
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>W3Cschool在線教程(w3cschool.cn)</title>
<script>
function displayResult(){
document.getElementById("myHeader1").colSpan="2";
}
</script>
</head>
<body>
<table border="1">
<tr>
<th id="myHeader1">月份</th>
<th id="myHeader2">存款</th>
</tr>
<tr>
<td>January</td>
<td>$100.00</td>
</tr>
<tr>
<td>February</td>
<td>$10.00</td>
</tr>
<tr>
<td>March</td>
<td>$80.00</td>
</tr>
</table>
<br>
<button type="button" onclick="displayResult()">改變第一個(gè)單元格的橫跨列數(shù)</button>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>W3Cschool在線教程(w3cschool.cn)</title>
<script>
function displayResult(){
document.getElementById("myHeader1").colSpan="2";
}
</script>
</head>
<body>
<table border="1">
<tr>
<th id="myHeader1">月份</th>
<th id="myHeader2">存款</th>
</tr>
<tr>
<td>January</td>
<td>$100.00</td>
</tr>
<tr>
<td>February</td>
<td>$10.00</td>
</tr>
<tr>
<td>March</td>
<td>$80.00</td>
</tr>
</table>
<br>
<button type="button" onclick="displayResult()">改變第一個(gè)單元格的橫跨列數(shù)</button>
</body>
</html>
嘗試一下 ?
td/th 對(duì)象
更多建議: