【发布时间】:2018-07-11 09:06:07
【问题描述】:
我想制作几个复选框以及 “全选” 复选框。功能如下:
- 选中复选框以显示表格列。取消选中 复选框/es 隐藏表格列/s - (切换)
- 选中“全选”复选框以显示表格的所有列。
取消选中“全选”复选框以隐藏表格的所有列 - (切换)。 - 如果选中“全选”复选框,则任何先前标记的 该复选框不应显示为选中状态。
- 如果选中任何其他复选框,则不会对表格列产生影响, 如果选中“全选”复选框。
$("input:checkbox:not(:checked)").each(function() {
var column = "table ." + $(this).attr("name");
$(column).hide();
});
$("input:checkbox").click(function(){
var column = "table ." + $(this).attr("name");
$(column).toggle();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!DOCTYPE html>
<html>
<head>
<title>Check Box</title>
</head>
<body>
<p><input type="checkbox" name="all" checked> Select All</p>
<p><input type="checkbox" name="symbol" checked> symbol</p>
<p><input type="checkbox" name="priceChange" checked> priceChange</p>
<p><input type="checkbox" name="priceChangePercent" checked> priceChangePercent</p>
<p><input type="checkbox" name="weightedAvgPrice" checked> weightedAvgPrice</p>
<table id="myTable" class="tablesorter">
<thead>
<tr>
<th class="symbol all">symbol</th>
<th class="priceChange all">priceChange</th>
<th class="priceChangePercent all">priceChangePercent</th>
<th class="weightedAvgPrice all">weightedAvgPrice</th>
</tr>
</thead>
</table>
<script type="text/javascript">
$("all").click(function () {
$(".checkBoxClass").prop('checked', $(this).prop('checked'));
});
</script>
</body>
</html>
【问题讨论】:
标签: javascript jquery html checkbox html-table