Created
July 10, 2013 07:59
-
-
Save ituki/5964303 to your computer and use it in GitHub Desktop.
jQueryで全選択・全解除はprop使う ref: http://qiita.com/ituki_b/items/17eab8c38a2ad5392660
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="allCheck"> | |
<input type="checkbox" id="allCheck01"><label for="allCheck01">全選択・全解除</label> | |
</div> | |
<div> | |
<input type="checkbox" id="check01"><label for="check01">アイテム01</label> | |
<input type="checkbox" id="check02"><label for="check02">アイテム02</label> | |
<input type="checkbox" id="check03"><label for="check03">アイテム03</label> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('.allCheck input,.allCheck label').click(function(){ //全選択・全解除をクリックしたとき | |
var items = $(this).closest('.allCheck').next().find('input'); | |
if($(this).is(':checked')) { //全選択・全解除がcheckedだったら | |
$(items).prop('checked', true); //アイテムを全部checkedにする | |
} else { //全選択・全解除がcheckedじゃなかったら | |
$(items).prop('checked', false); //アイテムを全部checkedはずす | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment