<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
}
</style>
</head>
<body>
<h3>如何访问 COL 元素的演示</h3>
<table>
<colgroup>
<col id="myCol" span="2" style="background-color:red">
<col style="background-color:yellow">
</colgroup>
<tr>
<th>ISBN</th>
<th>Title</th>
<th>Price</th>
</tr>
<tr>
<td>3476896</td>
<td>我的第一个 HTML</td>
<td>$53</td>
</tr>
<tr>
<td>5869207</td>
<td>我的第一个 CSS</td>
<td>$49</td>
</tr>
</table>
<p>单击该按钮可获取 COL 元素应跨越的列数。</p>
<button onclick="myFunction()">试一试</button>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.getElementById("myCol").span;
document.getElementById("demo").innerHTML = x;