td/th colSpan 属性

td/th 对象参考手册 td/th 对象

定义和用法

colSpan 属性可设置或返回表元横跨的列数。

语法

设置 colSpan 属性:

tdObject.colSpan="number"

或者

thObject.colSpan="number"

返回 colSpan 属性:

tdObject.colSpan

或者

thObject.colSpan

Tip: There is no default value for the colSpan property.

描述
number 定义横跨的列数


浏览器支持

Internet ExplorerFirefoxOperaGoogle ChromeSafari

所有主要浏览器都支持 colSpan 属性


实例

实例

下面的例子更改了表元横跨的列数:

<html>
<head>
<script>
function displayResult()
{
document.getElementById("myHeader1").colSpan="2";
}
</script>
</head>
<body>

<table border="1">
  <tr>
    <th id="myHeader1">Month</th>
    <th id="myHeader2">Savings</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()">Change colSpan for the first cell</button>

</body>
</html>

尝试一下 »


td/th 对象参考手册 td/th 对象