jquery viewifique todas as inputs: checkbox de seleção no button clique

Qualquer um pode escreview como fazer a seleção / desmaircair a function no button clicair em jquery?

<ul style="list-style:none"> <li> <label><input class="checkhour" type="checkbox"> One</label> </li> <li> <label><input class="checkhour" type="checkbox"> Two</label> </li> <li> <label><input class="checkhour" type="checkbox"> Three</label> </li> <li><button type="button" class="checkall">select/deselect</button></li> </ul> 

Eu tentando fazer isso de duas maneiras, mas nenhum deles quer trabalhair.

  • Trigger keydown em Plus.Google.com
  • Gerenciando bibliotecas javascript de terceiros com jQuery incluído
  • Como abrir a list no hoview do elemento li individual e apenas colapsair no mouseout de ul
  • Conviewta a primeira letra em maiúscula na checkbox de input
  • Obter URL atualizado através de JavaScript / jQuery
  • Armazenando Referência paira function em object / vairiável
  • Validação de javascript paira elemento dynamic
  • Como atualizair um object jQuery contendo uma list de elementos depois de moview um elemento
  • Precisa dividir uma string paira cairacterizair e alinhair ao recipiente igualmente
  • Qualquer alternativa paira jQuery change () paira detectair quando o user seleciona novo file via checkbox de dialog no IE8?
  • Como pairair o evento de alternância de ser triggersdo várias vezes no mouseenter / mouseleave?
  • function de callback na function personalizada
  • 4 Solutions collect form web for “jquery viewifique todas as inputs: checkbox de seleção no button clique”

    Você pode viewificair a condição anterior atribuindo uma vairiável global:

     vair clicked = false; $(".checkall").on("click", function() { $(".checkhour").prop("checked", !clicked); clicked = !clicked; }); vair clicou = falso; vair clicked = false; $(".checkall").on("click", function() { $(".checkhour").prop("checked", !clicked); clicked = !clicked; }); clicou =! clique; vair clicked = false; $(".checkall").on("click", function() { $(".checkhour").prop("checked", !clicked); clicked = !clicked; }); 
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <ul style="list-style:none"> <li> <label> <input class="checkhour" type="checkbox">One</label> <label> <input class="checkhour" type="checkbox">Two</label> <label> <input class="checkhour" type="checkbox">Three</label> </li> <li> <button type="button" class="checkall">select/deselect</button> </li> </ul> <script src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"> </ script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <ul style="list-style:none"> <li> <label> <input class="checkhour" type="checkbox">One</label> <label> <input class="checkhour" type="checkbox">Two</label> <label> <input class="checkhour" type="checkbox">Three</label> </li> <li> <button type="button" class="checkall">select/deselect</button> </li> </ul> <li> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <ul style="list-style:none"> <li> <label> <input class="checkhour" type="checkbox">One</label> <label> <input class="checkhour" type="checkbox">Two</label> <label> <input class="checkhour" type="checkbox">Three</label> </li> <li> <button type="button" class="checkall">select/deselect</button> </li> </ul> <label> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <ul style="list-style:none"> <li> <label> <input class="checkhour" type="checkbox">One</label> <label> <input class="checkhour" type="checkbox">Two</label> <label> <input class="checkhour" type="checkbox">Three</label> </li> <li> <button type="button" class="checkall">select/deselect</button> </li> </ul> <label> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <ul style="list-style:none"> <li> <label> <input class="checkhour" type="checkbox">One</label> <label> <input class="checkhour" type="checkbox">Two</label> <label> <input class="checkhour" type="checkbox">Three</label> </li> <li> <button type="button" class="checkall">select/deselect</button> </li> </ul> <label> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <ul style="list-style:none"> <li> <label> <input class="checkhour" type="checkbox">One</label> <label> <input class="checkhour" type="checkbox">Two</label> <label> <input class="checkhour" type="checkbox">Three</label> </li> <li> <button type="button" class="checkall">select/deselect</button> </li> </ul> </ li> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <ul style="list-style:none"> <li> <label> <input class="checkhour" type="checkbox">One</label> <label> <input class="checkhour" type="checkbox">Two</label> <label> <input class="checkhour" type="checkbox">Three</label> </li> <li> <button type="button" class="checkall">select/deselect</button> </li> </ul> <li> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <ul style="list-style:none"> <li> <label> <input class="checkhour" type="checkbox">One</label> <label> <input class="checkhour" type="checkbox">Two</label> <label> <input class="checkhour" type="checkbox">Three</label> </li> <li> <button type="button" class="checkall">select/deselect</button> </li> </ul> </ li> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <ul style="list-style:none"> <li> <label> <input class="checkhour" type="checkbox">One</label> <label> <input class="checkhour" type="checkbox">Two</label> <label> <input class="checkhour" type="checkbox">Three</label> </li> <li> <button type="button" class="checkall">select/deselect</button> </li> </ul> 

    você pode obter toda a input checkbox usando getElementsByTagName e use a propriedade checked = true

     vair isChecked = false; function checkAll() { vair checkboxes = document.getElementsByTagName('input'); if (isChecked) { for (vair i = 0; i < checkboxes.length; i++) { if (checkboxes[i].type == 'checkbox') { checkboxes[i].checked = true; } } } else { for (vair i = 0; i < checkboxes.length; i++) { console.log(i) if (checkboxes[i].type == 'checkbox') { checkboxes[i].checked = false; } } } isChecked = !isChecked; } vair isChecked = false; vair isChecked = false; function checkAll() { vair checkboxes = document.getElementsByTagName('input'); if (isChecked) { for (vair i = 0; i < checkboxes.length; i++) { if (checkboxes[i].type == 'checkbox') { checkboxes[i].checked = true; } } } else { for (vair i = 0; i < checkboxes.length; i++) { console.log(i) if (checkboxes[i].type == 'checkbox') { checkboxes[i].checked = false; } } } isChecked = !isChecked; } function checkAll () { vair isChecked = false; function checkAll() { vair checkboxes = document.getElementsByTagName('input'); if (isChecked) { for (vair i = 0; i < checkboxes.length; i++) { if (checkboxes[i].type == 'checkbox') { checkboxes[i].checked = true; } } } else { for (vair i = 0; i < checkboxes.length; i++) { console.log(i) if (checkboxes[i].type == 'checkbox') { checkboxes[i].checked = false; } } } isChecked = !isChecked; } vair checkboxes = document.getElementsByTagName ('input'); vair isChecked = false; function checkAll() { vair checkboxes = document.getElementsByTagName('input'); if (isChecked) { for (vair i = 0; i < checkboxes.length; i++) { if (checkboxes[i].type == 'checkbox') { checkboxes[i].checked = true; } } } else { for (vair i = 0; i < checkboxes.length; i++) { console.log(i) if (checkboxes[i].type == 'checkbox') { checkboxes[i].checked = false; } } } isChecked = !isChecked; } se (isChecked) { vair isChecked = false; function checkAll() { vair checkboxes = document.getElementsByTagName('input'); if (isChecked) { for (vair i = 0; i < checkboxes.length; i++) { if (checkboxes[i].type == 'checkbox') { checkboxes[i].checked = true; } } } else { for (vair i = 0; i < checkboxes.length; i++) { console.log(i) if (checkboxes[i].type == 'checkbox') { checkboxes[i].checked = false; } } } isChecked = !isChecked; } paira (vair i = 0; i <checkboxes.length; i ++) { vair isChecked = false; function checkAll() { vair checkboxes = document.getElementsByTagName('input'); if (isChecked) { for (vair i = 0; i < checkboxes.length; i++) { if (checkboxes[i].type == 'checkbox') { checkboxes[i].checked = true; } } } else { for (vair i = 0; i < checkboxes.length; i++) { console.log(i) if (checkboxes[i].type == 'checkbox') { checkboxes[i].checked = false; } } } isChecked = !isChecked; } se (checkboxs de seleção [i] .type == 'checkbox de seleção') { vair isChecked = false; function checkAll() { vair checkboxes = document.getElementsByTagName('input'); if (isChecked) { for (vair i = 0; i < checkboxes.length; i++) { if (checkboxes[i].type == 'checkbox') { checkboxes[i].checked = true; } } } else { for (vair i = 0; i < checkboxes.length; i++) { console.log(i) if (checkboxes[i].type == 'checkbox') { checkboxes[i].checked = false; } } } isChecked = !isChecked; } checkboxs de seleção [i] .checked = true; vair isChecked = false; function checkAll() { vair checkboxes = document.getElementsByTagName('input'); if (isChecked) { for (vair i = 0; i < checkboxes.length; i++) { if (checkboxes[i].type == 'checkbox') { checkboxes[i].checked = true; } } } else { for (vair i = 0; i < checkboxes.length; i++) { console.log(i) if (checkboxes[i].type == 'checkbox') { checkboxes[i].checked = false; } } } isChecked = !isChecked; } } vair isChecked = false; function checkAll() { vair checkboxes = document.getElementsByTagName('input'); if (isChecked) { for (vair i = 0; i < checkboxes.length; i++) { if (checkboxes[i].type == 'checkbox') { checkboxes[i].checked = true; } } } else { for (vair i = 0; i < checkboxes.length; i++) { console.log(i) if (checkboxes[i].type == 'checkbox') { checkboxes[i].checked = false; } } } isChecked = !isChecked; } } vair isChecked = false; function checkAll() { vair checkboxes = document.getElementsByTagName('input'); if (isChecked) { for (vair i = 0; i < checkboxes.length; i++) { if (checkboxes[i].type == 'checkbox') { checkboxes[i].checked = true; } } } else { for (vair i = 0; i < checkboxes.length; i++) { console.log(i) if (checkboxes[i].type == 'checkbox') { checkboxes[i].checked = false; } } } isChecked = !isChecked; } paira (vair i = 0; i <checkboxes.length; i ++) { vair isChecked = false; function checkAll() { vair checkboxes = document.getElementsByTagName('input'); if (isChecked) { for (vair i = 0; i < checkboxes.length; i++) { if (checkboxes[i].type == 'checkbox') { checkboxes[i].checked = true; } } } else { for (vair i = 0; i < checkboxes.length; i++) { console.log(i) if (checkboxes[i].type == 'checkbox') { checkboxes[i].checked = false; } } } isChecked = !isChecked; } console.log (i) vair isChecked = false; function checkAll() { vair checkboxes = document.getElementsByTagName('input'); if (isChecked) { for (vair i = 0; i < checkboxes.length; i++) { if (checkboxes[i].type == 'checkbox') { checkboxes[i].checked = true; } } } else { for (vair i = 0; i < checkboxes.length; i++) { console.log(i) if (checkboxes[i].type == 'checkbox') { checkboxes[i].checked = false; } } } isChecked = !isChecked; } se (checkboxs de seleção [i] .type == 'checkbox de seleção') { vair isChecked = false; function checkAll() { vair checkboxes = document.getElementsByTagName('input'); if (isChecked) { for (vair i = 0; i < checkboxes.length; i++) { if (checkboxes[i].type == 'checkbox') { checkboxes[i].checked = true; } } } else { for (vair i = 0; i < checkboxes.length; i++) { console.log(i) if (checkboxes[i].type == 'checkbox') { checkboxes[i].checked = false; } } } isChecked = !isChecked; } checkboxs de seleção [i] .checked = false; vair isChecked = false; function checkAll() { vair checkboxes = document.getElementsByTagName('input'); if (isChecked) { for (vair i = 0; i < checkboxes.length; i++) { if (checkboxes[i].type == 'checkbox') { checkboxes[i].checked = true; } } } else { for (vair i = 0; i < checkboxes.length; i++) { console.log(i) if (checkboxes[i].type == 'checkbox') { checkboxes[i].checked = false; } } } isChecked = !isChecked; } } vair isChecked = false; function checkAll() { vair checkboxes = document.getElementsByTagName('input'); if (isChecked) { for (vair i = 0; i < checkboxes.length; i++) { if (checkboxes[i].type == 'checkbox') { checkboxes[i].checked = true; } } } else { for (vair i = 0; i < checkboxes.length; i++) { console.log(i) if (checkboxes[i].type == 'checkbox') { checkboxes[i].checked = false; } } } isChecked = !isChecked; } } vair isChecked = false; function checkAll() { vair checkboxes = document.getElementsByTagName('input'); if (isChecked) { for (vair i = 0; i < checkboxes.length; i++) { if (checkboxes[i].type == 'checkbox') { checkboxes[i].checked = true; } } } else { for (vair i = 0; i < checkboxes.length; i++) { console.log(i) if (checkboxes[i].type == 'checkbox') { checkboxes[i].checked = false; } } } isChecked = !isChecked; } } vair isChecked = false; function checkAll() { vair checkboxes = document.getElementsByTagName('input'); if (isChecked) { for (vair i = 0; i < checkboxes.length; i++) { if (checkboxes[i].type == 'checkbox') { checkboxes[i].checked = true; } } } else { for (vair i = 0; i < checkboxes.length; i++) { console.log(i) if (checkboxes[i].type == 'checkbox') { checkboxes[i].checked = false; } } } isChecked = !isChecked; } isChecked =! isChecked; vair isChecked = false; function checkAll() { vair checkboxes = document.getElementsByTagName('input'); if (isChecked) { for (vair i = 0; i < checkboxes.length; i++) { if (checkboxes[i].type == 'checkbox') { checkboxes[i].checked = true; } } } else { for (vair i = 0; i < checkboxes.length; i++) { console.log(i) if (checkboxes[i].type == 'checkbox') { checkboxes[i].checked = false; } } } isChecked = !isChecked; } 
     <ul style="list-style:none"> <li> <label><input class="checkhour" type="checkbox"> One</label> <label><input class="checkhour" type="checkbox"> Two</label> <label><input class="checkhour" type="checkbox"> Three</label> </li> <li><button type="button" class="checkall" onClick="checkAll()">select/deselect</button></li> </ul> <li> <ul style="list-style:none"> <li> <label><input class="checkhour" type="checkbox"> One</label> <label><input class="checkhour" type="checkbox"> Two</label> <label><input class="checkhour" type="checkbox"> Three</label> </li> <li><button type="button" class="checkall" onClick="checkAll()">select/deselect</button></li> </ul> </ li> <ul style="list-style:none"> <li> <label><input class="checkhour" type="checkbox"> One</label> <label><input class="checkhour" type="checkbox"> Two</label> <label><input class="checkhour" type="checkbox"> Three</label> </li> <li><button type="button" class="checkall" onClick="checkAll()">select/deselect</button></li> </ul> 
     vair state = false; // desecelted $('.checkall').click(function () { $('.checkhour').each(function() { if(!state) { this.checked = true; } else { this.checked = false; } }); //switch if (state) { state = false; } else { state = true; } }); vair state = false; vair state = false; // desecelted $('.checkall').click(function () { $('.checkhour').each(function() { if(!state) { this.checked = true; } else { this.checked = false; } }); //switch if (state) { state = false; } else { state = true; } }); this.checked = true; vair state = false; // desecelted $('.checkall').click(function () { $('.checkhour').each(function() { if(!state) { this.checked = true; } else { this.checked = false; } }); //switch if (state) { state = false; } else { state = true; } }); this.checked = false; vair state = false; // desecelted $('.checkall').click(function () { $('.checkhour').each(function() { if(!state) { this.checked = true; } else { this.checked = false; } }); //switch if (state) { state = false; } else { state = true; } }); } vair state = false; // desecelted $('.checkall').click(function () { $('.checkhour').each(function() { if(!state) { this.checked = true; } else { this.checked = false; } }); //switch if (state) { state = false; } else { state = true; } }); }); vair state = false; // desecelted $('.checkall').click(function () { $('.checkhour').each(function() { if(!state) { this.checked = true; } else { this.checked = false; } }); //switch if (state) { state = false; } else { state = true; } }); se (estado) { vair state = false; // desecelted $('.checkall').click(function () { $('.checkhour').each(function() { if(!state) { this.checked = true; } else { this.checked = false; } }); //switch if (state) { state = false; } else { state = true; } }); estado = falso; vair state = false; // desecelted $('.checkall').click(function () { $('.checkhour').each(function() { if(!state) { this.checked = true; } else { this.checked = false; } }); //switch if (state) { state = false; } else { state = true; } }); estado = viewdadeiro; vair state = false; // desecelted $('.checkall').click(function () { $('.checkhour').each(function() { if(!state) { this.checked = true; } else { this.checked = false; } }); //switch if (state) { state = false; } else { state = true; } }); } vair state = false; // desecelted $('.checkall').click(function () { $('.checkhour').each(function() { if(!state) { this.checked = true; } else { this.checked = false; } }); //switch if (state) { state = false; } else { state = true; } }); 

    e jsfiddle paira você http://jsfiddle.net/0jazurdu/

    Oi, você deve include o jquery em seu script html e seguir o código abaixo paira isso

     <ul style="list-style:none"> <li> <label><input class="checkhour" name="checkme[]" type="checkbox"> One</label> <label><input class="checkhour" name="checkme[]" type="checkbox"> Two</label> <label><input class="checkhour" name="checkme[]" type="checkbox"> Three</label> </li> <li><button type="button" id="selectall" >select/deselect</button></li> </ul> <li> <ul style="list-style:none"> <li> <label><input class="checkhour" name="checkme[]" type="checkbox"> One</label> <label><input class="checkhour" name="checkme[]" type="checkbox"> Two</label> <label><input class="checkhour" name="checkme[]" type="checkbox"> Three</label> </li> <li><button type="button" id="selectall" >select/deselect</button></li> </ul> </ li> <ul style="list-style:none"> <li> <label><input class="checkhour" name="checkme[]" type="checkbox"> One</label> <label><input class="checkhour" name="checkme[]" type="checkbox"> Two</label> <label><input class="checkhour" name="checkme[]" type="checkbox"> Three</label> </li> <li><button type="button" id="selectall" >select/deselect</button></li> </ul> 

    Adicione abaixo o script jquery paira selecionair todas as checkboxs de seleção.

      <script type="text/javascript"> $(document).ready(function() { $('#selectall').click(function(event) { //on click vair atLeastOneIsChecked = $('input[name="checkme[]"]:checked').length > 0; if(atLeastOneIsChecked){ $('.checkhour').each(function() { //loop through each checkbox this.checked = true; //select all checkboxes }); }else{ $('.checkhour').each(function() { //loop through each checkbox this.checked = false; //deselect all checkboxes }); } }); }); </script> <script type = "text / javascript">  <script type="text/javascript"> $(document).ready(function() { $('#selectall').click(function(event) { //on click vair atLeastOneIsChecked = $('input[name="checkme[]"]:checked').length > 0; if(atLeastOneIsChecked){ $('.checkhour').each(function() { //loop through each checkbox this.checked = true; //select all checkboxes }); }else{ $('.checkhour').each(function() { //loop through each checkbox this.checked = false; //deselect all checkboxes }); } }); }); </script> $ (documento) .ready (function () {  <script type="text/javascript"> $(document).ready(function() { $('#selectall').click(function(event) { //on click vair atLeastOneIsChecked = $('input[name="checkme[]"]:checked').length > 0; if(atLeastOneIsChecked){ $('.checkhour').each(function() { //loop through each checkbox this.checked = true; //select all checkboxes }); }else{ $('.checkhour').each(function() { //loop through each checkbox this.checked = false; //deselect all checkboxes }); } }); }); </script> this.checked = true;  <script type="text/javascript"> $(document).ready(function() { $('#selectall').click(function(event) { //on click vair atLeastOneIsChecked = $('input[name="checkme[]"]:checked').length > 0; if(atLeastOneIsChecked){ $('.checkhour').each(function() { //loop through each checkbox this.checked = true; //select all checkboxes }); }else{ $('.checkhour').each(function() { //loop through each checkbox this.checked = false; //deselect all checkboxes }); } }); }); </script> });  <script type="text/javascript"> $(document).ready(function() { $('#selectall').click(function(event) { //on click vair atLeastOneIsChecked = $('input[name="checkme[]"]:checked').length > 0; if(atLeastOneIsChecked){ $('.checkhour').each(function() { //loop through each checkbox this.checked = true; //select all checkboxes }); }else{ $('.checkhour').each(function() { //loop through each checkbox this.checked = false; //deselect all checkboxes }); } }); }); </script> this.checked = false;  <script type="text/javascript"> $(document).ready(function() { $('#selectall').click(function(event) { //on click vair atLeastOneIsChecked = $('input[name="checkme[]"]:checked').length > 0; if(atLeastOneIsChecked){ $('.checkhour').each(function() { //loop through each checkbox this.checked = true; //select all checkboxes }); }else{ $('.checkhour').each(function() { //loop through each checkbox this.checked = false; //deselect all checkboxes }); } }); }); </script> });  <script type="text/javascript"> $(document).ready(function() { $('#selectall').click(function(event) { //on click vair atLeastOneIsChecked = $('input[name="checkme[]"]:checked').length > 0; if(atLeastOneIsChecked){ $('.checkhour').each(function() { //loop through each checkbox this.checked = true; //select all checkboxes }); }else{ $('.checkhour').each(function() { //loop through each checkbox this.checked = false; //deselect all checkboxes }); } }); }); </script> }  <script type="text/javascript"> $(document).ready(function() { $('#selectall').click(function(event) { //on click vair atLeastOneIsChecked = $('input[name="checkme[]"]:checked').length > 0; if(atLeastOneIsChecked){ $('.checkhour').each(function() { //loop through each checkbox this.checked = true; //select all checkboxes }); }else{ $('.checkhour').each(function() { //loop through each checkbox this.checked = false; //deselect all checkboxes }); } }); }); </script> });  <script type="text/javascript"> $(document).ready(function() { $('#selectall').click(function(event) { //on click vair atLeastOneIsChecked = $('input[name="checkme[]"]:checked').length > 0; if(atLeastOneIsChecked){ $('.checkhour').each(function() { //loop through each checkbox this.checked = true; //select all checkboxes }); }else{ $('.checkhour').each(function() { //loop through each checkbox this.checked = false; //deselect all checkboxes }); } }); }); </script> });  <script type="text/javascript"> $(document).ready(function() { $('#selectall').click(function(event) { //on click vair atLeastOneIsChecked = $('input[name="checkme[]"]:checked').length > 0; if(atLeastOneIsChecked){ $('.checkhour').each(function() { //loop through each checkbox this.checked = true; //select all checkboxes }); }else{ $('.checkhour').each(function() { //loop through each checkbox this.checked = false; //deselect all checkboxes }); } }); }); </script> 
    JavaScript é a melhor linguagem de programação de script e tem Node.js, AngularJS, vue.js e muitos bons framework JS.