Select All Checkbox

后端 未结 4 1033
面向向阳花
面向向阳花 2020-12-03 19:47

I have a webpage that returns search results in a table/form. I would like to have a select all checkbox, that would select all the checkboxes for the search results. My c

相关标签:
4条回答
  • 2020-12-03 20:09

    You can use jquery to do this in simpler way

    $("form input:checkbox").attr('checked','true');
    
    0 讨论(0)
  • 2020-12-03 20:10

    Add a class to each checkbox input.

    echo '<input type="checkbox" name="selected[]" value="'.$row['order_number'].'" class="yourclass" />';

    Then in javascript iterate over all input fields in the docment and check whether they have both type="checkbox" and class="yourclass". And set all of them to CHECKED!

    0 讨论(0)
  • 2020-12-03 20:15
    var form = document.getElementsById('form_id');
    var checkBoxes = form.getElementsByTagName('input');
    for (var i in checkBoxes)
    {
       if (checkBoxes[i].type=="checkbox")
          checkBoxes[i].checked = true; 
    }
    
    0 讨论(0)
  • 2020-12-03 20:20

    Best solution 4 u is a Jquery script

    /*Unik Checkbox to mark/desmark other checkboxes*/
    <input type="checkbox" onclick="selectAllCheckBoxes(this)" id="checkBoxUnik"/>
    
    /*Several other Checkboxes inside loop*/
    <input type="checkbox" onclick="unselectCheckBoxUnik()" class="checkBoxInLoop" />
    
    <script>
        function selectAllCheckBoxes(obj){
            $('input:checkbox:not(:disabled).checkBoxInLoop').prop('checked', jQuery(obj).prop('checked'));
        }
    
        function unselectCheckBoxUnik(){
    
            /*first you verify if the quantity of checkboxes equals number of checkboxes*/
            a = $('input:checkbox:not(:disabled).checkBoxInLoop:checked').size();
            b = $('input:checkbox:not(:disabled).checkBoxInLoop').size();
    
            /*if equals, mark a checkBoxUnik*/
            ((a == b)? $('#checkBoxUnik').prop("checked", true) : $('#checkBoxUnik').prop("checked", false));
        }
    </script>
    
    0 讨论(0)
提交回复
热议问题