Check all Checkboxes in Page via Developer Tools

后端 未结 8 1326
野性不改
野性不改 2021-01-30 05:13

I have a loop that creates 20 check-boxes in the same page (it creates different forms). I want via chrome developer tools to

相关标签:
8条回答
  • 2021-01-30 06:00

    To modify the accepted answer slightly, if you're trying to check all of the boxes on some services, such as Loom.com, then you'll need to click each one instead of just setting them to "checked" status, otherwise the functionality doesn't work as expected.

    Here's the code to do that:

    (function() {
        var aa = document.querySelectorAll("input[type=checkbox]");
        for (var i = 0; i < aa.length; i++){
            aa[i].click();
        }
    })()
    

    Please note that longer lists of checkboxes will cause the page to pause temporarily as all checkboxes get automatically clicked for you.

    0 讨论(0)
  • 2021-01-30 06:02
    (function() {
        var aa= document.getElementsByTagName("input");
        for (var i =0; i < aa.length; i++){
            if (aa[i].type == 'checkbox')
                aa[i].checked = true;
        }
    })()
    

    With up to date browsers can use document.querySelectorAll

    (function() {
        var aa = document.querySelectorAll("input[type=checkbox]");
        for (var i = 0; i < aa.length; i++){
            aa[i].checked = true;
        }
    })()
    
    0 讨论(0)
提交回复
热议问题