Select all checkboxes in a form based on JQuery

key code

HTML


<table id="table">
    <thead>
        <th><input class="group-checkable" type="checkbox" data-set="#table .checkboxes"/></th>
    </thead>
    <tbody>
        <tr><td><input class="checkboxes" type="checkbox"/></td></tr>
        <tr><td><input class="checkboxes" type="checkbox"/></td></tr>
        <tr><td><input class="checkboxes" type="checkbox"/></td></tr>
    </tbody>
</table>

JavaScript


$(function(){
    $('#table').find('.group-checkable').change(function(){
        var set = $(this).attr('data-set');
        var checked = $(this).is(':checked');
        $('set').each(function(){
            if(checked){
                $(this).prop('checked', true);
            } else {
                $(this).prop('checked', false);
            }
        })
    })
})

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324519036&siteId=291194637