【发布时间】:2012-06-14 17:31:59
【问题描述】:
小提琴是here。
我无法通过 colgroup 的 col id 抓取实际列来切换它。我的索引正确匹配,但我不明白如何使用 colgroup 的力量来抓取整个列。这是我目前的尝试(一直在小提琴的底部):
//Column Button Hider
$('fieldset.techtable input.column[type=checkbox]').on('change', function() {
var index = $(this).prevAll('input.column').length+2;
console.log(index);
$('fieldset.techtable' #col'+index').toggle()
//($('#col'+index).toggle());
});
这是表格和列组:
<section class="techtable">
<h1>Technologies / Compliance / Certifications</h1>
<table cellspacing="0">
<colgroup>
<col id="col0">
<col id="col1">
<col id="col2">
<col id="col3">
<col id="col4">
<col id="col5">
<col id="col6">
</colgroup>
<thead>
<tr>
<th>Category</th>
<th>Skill</th>
<th>Version(s)</th>
<th>Start Date</th>
<th>End Date</th>
<th>Elapsed Time</th>
<th>Expertise Rating</th>
</tr>
</thead>
<tbody>
<tr>
<td>Technology</td>
<td>J2EE</td>
<td>1.5, 1.6, 1.7</td>
<td>November, 2011</td>
<td></td>
<td></td>
<td>2</td>
</tr>
</tr>...repeating...</tr>
</tbody>
</table>
</section>
我想尝试利用 colgroup 的力量,但不确定是否应该使用类 ID(如果是,在哪里?在 col 组 ID 上,<th>?或每个 <td>?)。
<th>s 是否干扰了<colgroup>?也许措辞更好,我应该引用 th 而不是尝试使用 colgroup?
指出正确的语法方向是有帮助的,并且总是感谢提供帮助的代码行,但是对于这一点,我试图避免将其扩展到更多代码行,除非我忽略了方法。我假设我不仅正确地抓住了 col id,而且您的反馈可能证明我错了。
【问题讨论】:
-
fieldset.techtable在哪里?我看到的只是section.techtable -
您是否试图通过在 colgroup 中隐藏 col 来隐藏整个表格列?我无法让它真正做任何事情。 jsfiddle.net/HvGLu 至于你关于
th的问题,隐藏th不会隐藏它对应的td,它们必须分别隐藏。
标签: javascript jquery html-table toggle colgroup