HTML DOM td / th properti colspan
Definisi dan Penggunaan
colspan set properti atau mengembalikan jumlah kolom tabel membentang yuan.
tatabahasa
Pengaturan properti colspan:
tdObject.colSpan="number"
或者
thObject.colSpan="number"
或者
thObject.colSpan="number"
Sifat Kembali colspan:
tdObject.colSpan
或者
thObject.colSpan
或者
thObject.colSpan
Tip: Tidak ada nilai default untuk properti colspan.
值 | 描述 |
---|---|
number | 定义横跨的列数 |
Dukungan Browser
Semua browser utama mendukung properti colspan
contoh
contoh
Contoh berikut mengubah jumlah kolom seluruh elemen tabel:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.com)</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()">改变第一个单元格的横跨列数</button>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.com)</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()">改变第一个单元格的横跨列数</button>
</body>
</html>
Coba »
td / benda th