如果我是正确的,这就是您要执行的操作:
使用<colgroup>标签:
HTML:
<table border="1">
<colgroup>
<colgroup>
<colgroup span="2">
<colgroup>
<tr>
<th scope="colgroup">A</th>
<th scope="colgroup">B</th>
<th colspan="2" scope="colgroup">C</th>
<th scope="colgroup">D</th>
</tr>
<tr>
<td rowspan="3">1</td>
<td rowspan="3">2</td>
<td rowspan="3">3</td>
<td>3</td>
<td>4</td>
</tr>
<tr>
<td>3</td>
<td>4</td>
</tr>
<tr>
<td>3</td>
<td>4</td>
</tr>
<tr>
<td>3</td>
<td>4</td>
<td>3</td>
<td>4</td>
<td>4</td>
</tr>
</table>
<br>
<button class="col1">Col 1</button>
<button class="col2">Col 2</button>
<button class="col3">Col 3</button>
<button class="col4">Col 4</button>
<button class="reload">Reload</button>
JS:
$(".col1").click(function() {
$('colgroup:nth-child(1)').css("background-color", "red");
});
$(".col2").click(function() {
$('colgroup:nth-child(2)').css("background-color", "red");
});
$(".col3").click(function() {
$('colgroup:nth-child(3)').css("background-color", "red");
});
$(".col4").click(function() {
$('colgroup:nth-child(4)').css("background-color", "red");
});
$(".reload").click(function() {
location.reload();
});
COLGROUP 方法小提琴链接: https://jsfiddle.net/devqnyg5/11/
使用<col>标签:
HTML:
<table border="1">
<col>
<col>
<col>
<col>
<col>
<tr>
<th>A</th>
<th>B</th>
<th colspan="2">C</th>
<th>D</th>
</tr>
<tr>
<td rowspan="3">1</td>
<td rowspan="3">2</td>
<td rowspan="3">3</td>
<td>3</td>
<td>4</td>
</tr>
<tr>
<td>3</td>
<td>4</td>
</tr>
</table><br>
<button class="col1">Col 1</button>
<button class="col2">Col 2</button>
<button class="col3">Col 3</button>
<button class="col4">Col 4</button>
<button class="reload">Reload</button>
JS:
$(".col1").click(function() {
$('col:nth-child(1)').css("background-color", "red");
});
$(".col2").click(function() {
$('col:nth-child(2)').css("background-color", "red");
});
$(".col3").click(function() {
$('col:nth-child(3),col:nth-child(4)').css("background-color", "red");
});
$(".col4").click(function() {
$('col:nth-child(5)').css("background-color", "red");
});
$(".reload").click(function() {
location.reload();
});
COL 方法小提琴链接: https://jsfiddle.net/devqnyg5/9/