1
如何循環瀏覽我的所有複選框並檢索輸入「已選中或未選中」並傳遞給我的函數並隱藏或顯示我的列表?jquery循環顯示/隱藏n列的checbbox函數表
我的HTML
<div class="columnchecking">
<h1>Check/Uncheck for showing/hiding columns of table</h1>
<br />
<font size="4"><input id="formnamecheck" type="checkbox">Formname  </font>
<font size="4"><input id="typecheck" type="checkbox">Type  </font>
<font size="4"><input id="languagecheck" type="checkbox">Language  </font>
<font size="4"><input id="gpartcheck" type="checkbox">Gpart  </font>
</div>
<table>
<thead>
<tr>
<th>Formname</th>
<th>Formname</th>
<th>Type</th>
<th>Language</th>
<th>Gpart</th>
</tr>
</thead>
<tbody>
<tr>
<td>Test</td>
<td>Test</td>
<td>Test</td>
<td>Test</td>
</tr>
</tbody>
</table>
的Javascript:
<script type="text/javascript">
$(document).ready(function() {
$("#formnamecheck").click(function() {
if ($(this).is(':checked')) {
$('td:nth-child(n),th:nth-child(n)').hide();
} else {
$('td:nth-child(n),th:nth-child(n)').show();
}
});
});
其中N是我的第n列在我的表
謝謝您的回答,但是我不得不修改我的情況下工作和更改的.index() - 1和$(本)。是(「:檢查」)!),因爲我做n ot希望當我的頁面加載時默認隱藏列 – algorithmic
@algorithmic,不客氣。很高興能有所幫助。是的,的確,如果不添加'div'容器,'font'元素的索引數將從2開始,這就是爲什麼你必須添加'-1'。我很高興你明白了。 – Ionut
感謝您的澄清:) – algorithmic