Style emptyCells 屬性

Style 對象參考手冊 Style 對象

定義和用法

emptyCells 屬性設置或返回是否顯示表格中的空單元格的邊框和背景。

語法

設置 emptyCells 屬性:

Object.style.emptyCells="show|hide|inherit"

返回 emptyCells 屬性:

Object.style.emptyCells

描述
show 顯示空單元格的邊框和背景,即在空單元格周圍繪製邊框。
hide 隱藏空單元格的邊框和背景,即不在空單元格周圍繪製邊框。
inherit emptyCells 屬性的值從父元素繼承。


流覽器支持

Internet ExplorerFirefoxOperaGoogle ChromeSafari

所有主要流覽器都支持 emptyCells 屬性。

注意:不同流覽器中的默認值不同。在 IE、Chrome 和 Safari 流覽器中,默認值是 "show",而在 Firefox 和 Opera 流覽器中,默認值是 "hide"。

注意:IE7 及更早的版本不支持 emptyCells 屬性。IE8 只有規定了 !DOCTYPE 才支持 emptyCells 屬性。IE9 支持 emptyCells 屬性。


實例

實例

改變空單元格的顯示方式:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>IT研修(xuhuhu.com)</title>
<script>
function show(){
    document.getElementById("myTable").style.emptyCells="show";
}
function hide(){
    document.getElementById("myTable").style.emptyCells="hide";
}
</script>
</head>
<body>

<table id="myTable" border="1">
    <tr>
        <th>Month</th>
        <th>Savings</th>
    </tr>
    <tr>
        <td>January</td>
        <td>$100</td>
    </tr>
    <tr>
        <td>February</td>
        <td></td>
    </tr>
</table>
<br>
<button type="button" onclick="show()">顯示空單元格</button>
<button type="button" onclick="hide()">隱藏空單元格</button>
<p><b>注意:</b> Internet Explorer 8 及更早版本要支持empty-cells屬性必須聲明 !DOCTYPE 。</p>

</body>
</html>



Style 對象參考手冊 Style 對象