Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/424.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jquery统一选择和取消选择所有复选框_Javascript_Jquery - Fatal编程技术网

Javascript jquery统一选择和取消选择所有复选框

Javascript jquery统一选择和取消选择所有复选框,javascript,jquery,Javascript,Jquery,我对“全选/取消选择”复选框有问题 此处编码 <input type="checkbox" value="" onclick="checkedAll();" name="checkall" id="checkall"/> function checkedAll() { $('.all span').click(function () { if(document.getElementById("checkall").checked == true)

我对“全选/取消选择”复选框有问题

此处编码

<input type="checkbox" value="" onclick="checkedAll();" name="checkall" id="checkall"/>

  function checkedAll() {
      $('.all span').click(function () {
       if(document.getElementById("checkall").checked == true)
       {
         $('#uniform-undefined span').addClass('checked');      
       }
       else
       {
         $('#uniform-undefined span').removeClass('checked');
       }
     });
     $.uniform.update();
   }
并且没有任何复选框处于活动状态

<li><label><div id="uniform-undefined" class="checker">">
   <span class="checked"><input type="checkbox" value="F2" style="opacity: 0;"></span>
   </div><b>1 </b>
 </label></li>

<li><label><div id="uniform-undefined" class="checker">
   <span class="checked"><input type="checkbox" value="F2" style="opacity: 0;"></span>
   </div><b>2 </b>
</label></li>

<li><label><div id="uniform-undefined" class="checker">
    <span class="checked"><input type="checkbox" value="F3" style="opacity: 0;"></span>
    </div><b>3 </b>
</label></li>
  • ”> 1.
  • 2.
  • 3.

  • 你的目标是这样吗

    $('document').ready(function(){
        $('#all').click(function(){
            if($(this).is(':checked')){
                $('.group').attr("checked",true);
            }
            else{
                $('.group').attr("checked",false);
            }
        })
    });
    
    看这个

    试试这个

      $('#all').on('click', function(){
            $(':checkbox').attr("checked",$(this).is(':checked'));
      });
    
    或者对于las版本

      $('#all').on('click', function(){
            $(':checkbox').prop("checked",$(this).is(':checked'));
      });
    
    看这个

    这是代码仅第一次正常工作。第二次,如果我单击“全选”复选框,它将不工作。它仅被选中。

    
    
    <script>
    $('document').ready(function(){
    
        $('#selectAll').click(function(){
            if($(this).is(':checked')){
                $('#uniform-undefined span').attr("class","checked");
            }
            else{
                $('#uniform-undefined span').attr("class","");
            }
        })
    });
    </script>
    
    $('document').ready(函数(){ $('#selectAll')。单击(函数(){ 如果($(this).is(':checked')){ $(“#统一未定义范围”).attr(“类”、“选中”); } 否则{ $(“#统一的未定义的跨度”).attr(“类”,“类”); } }) });
    最简单的解决方案调用uniform.update:

            $(".all span").each(function () {
                $(this).prop("checked", document.getElementById("checkall").checked );
            });
            $.uniform.update();
    

    您是否尝试一键选择全部?您在代码中尝试执行什么操作?您能否确保显示的代码正确且没有复制粘贴错误。您似乎在开始时有一个额外的
    “>
    ,并且您
    style=opacity:0;最后一组中的“
    缺少一个
    。只想确保问题不是由于奇怪的HTML造成的。如果只想选中所有复选框,请执行类似操作:
    $('input[type=checkbox')).attr('checked',true)
    ;JSFIDLE将非常受欢迎……我看到了您在那里所做的:),非常整洁。这很好,但对于最新的jQuery版本来说没有,因为它们删除了
    attr
    并添加了
    prop
    。因此,只需更新代码和ad
    prop
    而不是
    attr
    ,它就会很好地工作:)您应该使用属性“checked”,而不是属性“checked”$(“.组”).prop(“选中”);
    <script>
    $('document').ready(function(){
    
        $('#selectAll').click(function(){
            if($(this).is(':checked')){
                $('#uniform-undefined span').attr("class","checked");
            }
            else{
                $('#uniform-undefined span').attr("class","");
            }
        })
    });
    </script>
    
            $(".all span").each(function () {
                $(this).prop("checked", document.getElementById("checkall").checked );
            });
            $.uniform.update();