チェックボックスにチェックしたら他のも全部選択出来る

Ads

Result

jQuery

//クリックイベント
        $("#toggle").click(function(){
            //attr()ではなくprop()を使う
            $('.chkbox').prop('checked', $(this).prop('checked'));
        });

html

<input type="checkbox" id="toggle">Check toggle<br>
<br>
<input class="chkbox" type="checkbox" name="foo" value="1"> Example 01<br>
<input class="chkbox" type="checkbox" name="bar" value="2"> Example 02<br>
<input class="chkbox" type="checkbox" name="piyo" value="3"> Example 03<br>​
タイトルとURLをコピーしました