Select All checkbox by Javascript or console

后端 未结 9 1318
野性不改
野性不改 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:15

    Pure JS method, don't use jQuery.. its just silly for something so trivial.

    [].forEach.call( document.querySelectorAll('input[type="checkbox"]'),function(el){
           el.checked=true;
         }
    );​
    

    Live Demo

    To use it on any webpage you can paste this into the address bar

    javascript:[].forEach.call(document.querySelectorAll('input[type="checkbox"]'),function(el){el.checked=true});
    

    then drag that to your bookmarks, and you have a bookmarklet. Just click it whenever you need to use it on a page.

提交回复
热议问题