zoukankan      html  css  js  c++  java
  • checkbox属性checked="checked"通过js已设置,但是不勾选

    1.通过 attr('checked','checked') 来设置checkbox时,重复点击,虽然checked属性设置正确,但是checkbox没有被勾选 ,如下代码:(代码是全选功能)

    $('#ckAll').click(function(){
                if($('#ckAll ').attr('checked') == 'checked'){
                    $('#ckAll').removeAttr('checked');
                }else{
                    $('#ckAll').attr('checked','checked');
                }
                if($('#ckAll').attr('checked') == 'checked'){
                    $('.tab-list .ckbox').each(function(i,n){
                        $(n).attr('checked','checked');
                    });
                }else{
                    $('.tab-list .ckbox').each(function(i,n){
                        $(n).removeAttr('checked');
                    });
                }
            }); 

    2. 换成 prop('checked',true) ,当ckAll被选中时,所有列表checkbox都会被选中

    //用click或用 change

    $('#ckAll').click(function(){
                if($('#ckAll').prop('checked')){
                    $('.tab-list .ckbox').each(function(i,n){
                        $(n).prop('checked',true);
                    });
                }else{
                    $('.tab-list .ckbox').each(function(i,n){
                        $(n).prop('checked',false);
                    });
                }
            });

  • 相关阅读:
    「暑期集训day23」黑幕
    暑期集训day23考试整理
    「暑期集训day22」黑色
    暑期集训day22考试整理
    「暑期集训day21」往复
    「暑期集训day20」仰望
    日常报错
    Spring-Boot环境的快速搭建
    jsp和thymeleaf模板
    Boot的简单配置
  • 原文地址:https://www.cnblogs.com/hfdp/p/5095038.html
Copyright © 2011-2022 走看看