Select All checkbox by Javascript or console

后端 未结 9 1290
野性不改
野性不改 2021-01-31 05:01

I am having 100 Checkboxes on my web page. For testing purposes I want to tick all those boxes, but manually clicking is time consuming. Is there a possible way to get them tick

相关标签:
9条回答
  • 2021-01-31 05:27

    I provided answer to this question at Check all Checkboxes in Page via Developer Tools

    In short you can do it from dev tools console (F12) by:

    $$('input').map(i => i.checked = true)

    or

    $$('input[type="checkbox"').map(i => i.checked = true)

    0 讨论(0)
  • 2021-01-31 05:38

    Multiple Check All & Uncheck All Boxes

    All You Need to change is the tag 'name' to change the what its turing ON/OFF

    <FORM>
        <input type="checkbox" name="item0[]" onclick="CheckAll(this)" />
        <input type="checkbox" name="item0[]" value="1" />
        <input type="checkbox" name="item0[]" value="2" />
        <input type="checkbox" name="item0[]" value="3" />
        <br>
        <input type="checkbox" name="item1[]" onclick="CheckAll(this)" />
        <input type="checkbox" name="item1[]" value="a" />
        <input type="checkbox" name="item1[]" value="b" />
        <input type="checkbox" name="item1[]" value="c" />
        <br>
        <input type="checkbox" name="item2" onclick="CheckAll(this)" />
        <input type="checkbox" name="item2" value="a1" />
        <input type="checkbox" name="item2" value="b2" />
        <input type="checkbox" name="item2" value="bc" />
    </FORM>
    
    <script>
        function CheckAll(x)
        {
            var allInputs = document.getElementsByName(x.name);
            for (var i = 0, max = allInputs.length; i < max; i++) 
            {
                if (allInputs[i].type == 'checkbox')
                if (x.checked == true)
                    allInputs[i].checked = true;
                else
                    allInputs[i].checked = false;
            }
        }
    </script>
    
    0 讨论(0)
  • 2021-01-31 05:39

    by using jquery, simple as that

    $('input:checkbox').each(function () {
       // alert(this);
       $(this).attr('checked', true);
      });
    

    Or simply use

    $('input:checkbox').prop('checked', true);// use the property
    

    OR

     $('input:checkbox').attr('checked', true); // by using the attribute
    
    0 讨论(0)
提交回复
热议问题