チェックボックス機能のようなgmailを実装したい:CheckAllチェックボックスをクリックすると、リストされたすべてのチェックボックスが選択/選択解除され、リストされたすべてのチェックボックスが選択された場合、CheckAllチェックボックスがチェックされます。一部のチェックボックスのみがチェックされている場合、 - 記号チェックボックスが表示されます。
divを使用してロジックを実装しています。ロジックは次のとおりです。 HTML:
<table id="ViewTable" class="tableEffectfull">
<thead>
<tr>
<th class="selectCol"><div class="unCheckedCheckBoxAll"></div></th>
<th class="nosCol">Products</th>
</tr>
</thead>
<tr>
<td><div class="unCheckedCheckBox"></div></td>
<td>ABCD</td>
</tr>
<tr>
<td><div class="unCheckedCheckBox"></div></td>
<td>PQRS</td>
</tr>
</table>
CSS:
.unCheckedCheckBox{
width: 25px;
height: 25px;
margin-top: -4px;
background: transparent url(images/prettyCheckable-green.png) top left no-repeat;
}
.CheckedCheckBox{
background: transparent url(images/prettyCheckable-green.png) 0 -60px;
}
.unCheckedCheckBoxAll{
width: 25px;
height: 25px;
margin-top: -4px;
background: transparent url(images/Checkable-green.png) top left no-repeat;
}
.CheckedCheckBoxAll{
background: transparent url(images/Checkable-green.png) 0 -60px;
}
スクリプト: //更新されたスクリプト:
$(".unCheckedCheckBox").click(function () {
$(this).toggleClass('CheckedCheckBox');
$('.unCheckedCheckBoxAll').toggleClass('CheckedCheckBoxAll', $('.CheckedCheckBox').length == $(".unCheckedCheckBox").length)
});
$(".unCheckedCheckBoxAll").click(function () {
$(this).toggleClass('CheckedCheckBoxAll');
$('.unCheckedCheckBox').toggleClass('CheckedCheckBox')
});
問題は、リストされているすべてのチェックボックスが選択されている場合に何をすべきかがわからないことです。checkedAllチェックボックスをチェックしてください。一部がチェックされている場合、強調表示されたチェックボックスのみがcheckedAllに表示されます。
以下は私が使用している画像です: