HTML DOM Table cellSpacing 屬性用於設置或返回 <table> 元素的 cellSpacing 屬性的值。 cellSpacing 屬性用於定義單元格之間的空間。
注意:HTML5 不再支持此屬性。
用法
- 它返回 cellSpacing 屬性。
TableObject.cellSpacing
- 它用於設置 cellSpacing 屬性。
TableObject.cellSpacing = "pixels"
屬性值:它包含以像素為單位表示兩個單元格之間的空格數的數值。
返回值:它返回一個數值,以像素表示單元格之間的空間。
範例1:下麵的代碼返回 Table cellSpacing 屬性。
HTML
<!DOCTYPE html>
<html>
<head>
<title>
Table cellSpacing Property in HTML
</title>
<style>
table,
td {
border:1px solid green;
}
h1 {
color:green;
}
h2 {
font-family:Impact;
}
body {
text-align:center;
}
</style>
</head>
<body>
<h1>GeeksforGeeks</h1>
<h2>Table cellSpacing Property</h2>
<table id="GFG" align="center" cellspacing="20">
<thead>
<tr>
<th>Subject</th>
<th>Courses</th>
</tr>
</thead>
<tr>
<td>Java</td>
<td>Fork Java</td>
</tr>
<tr>
<td>Python</td>
<td>Fork Python</td>
</tr>
<tr>
<td>Placements</td>
<td>Sudo Placement</td>
</tr>
</table>
<br />
<button ondblclick="Table_Caption()">
Return CellPadding
</button>
<p id="sudo"></p>
<script>
function Table_Caption() {
var w = document.getElementById(
"GFG").cellSpacing;
document.getElementById(
"sudo").innerHTML = w + "PX";
}
</script>
</body>
</html>
輸出:
範例2:下麵的 HTML 代碼說明了如何設置 cellSpacing 屬性。
HTML
<!DOCTYPE html>
<html>
<head>
<title>
Table cellSpacing Property in HTML
</title>
<style>
table,
td {
border:1px solid green;
}
h1 {
color:green;
}
h2 {
font-family:Impact;
}
body {
text-align:center;
}
</style>
</head>
<body>
<h1>GeeksforGeeks</h1>
<h2>Table cellSpacing Property</h2>
<table id="GFG" align="center" cellspacing="20">
<thead>
<tr>
<th>Subject</th>
<th>Courses</th>
</tr>
</thead>
<tr>
<td>Java</td>
<td>Fork Java</td>
</tr>
<tr>
<td>Python</td>
<td>Fork Python</td>
</tr>
<tr>
<td>Placements</td>
<td>Sudo Placement</td>
</tr>
</table>
<br />
<button ondblclick="Table_Caption()">
Return CellPadding
</button>
<p id="sudo"></p>
<script>
function Table_Caption() {
// Pixel set
var w = (document.getElementById(
"GFG").cellSpacing = "5");
document.getElementById(
"sudo").innerHTML = w + "PX";
}
</script>
</body>
</html>
輸出:
支持的瀏覽器:
- 穀歌瀏覽器
- Firefox
- 蘋果Safari
- IE瀏覽器
- Opera
相關用法
- HTML <table> cellspacing屬性用法及代碼示例
- HTML Table tFoot用法及代碼示例
- HTML Table caption用法及代碼示例
- HTML Table tHead用法及代碼示例
- HTML DOM Table cellPadding屬性用法及代碼示例
- HTML DOM Table frame屬性用法及代碼示例
- HTML DOM Table Summary屬性用法及代碼示例
- HTML DOM Table rules屬性用法及代碼示例
- HTML Table width用法及代碼示例
- HTML DOM console.table()用法及代碼示例
- HTML DOM Table用法及代碼示例
- HTML DOM Table deleteRow()用法及代碼示例
- HTML DOM Table deleteTFoot()用法及代碼示例
- HTML DOM Table deleteCaption()用法及代碼示例
- HTML DOM Table deleteTHead()用法及代碼示例
注:本文由純淨天空篩選整理自ManasChhabra2大神的英文原創作品 HTML DOM Table cellSpacing Property。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。