zoukankan      html  css  js  c++  java
  • 问题1:jquery实现全选功能,第二次失效(已解决)

    问题:使用了attr("checked",true”)设置子复选框的被选状态,第一次执行功能正常,但第二次失效。

    解决方案:将attr("checked",true”) 换为prop("checked",true”),功能正确

    分析:在遇到属性值为true/false时,使用prop()。。。原理暂时不清楚

    附代码:

    //全选功能
    function checkAll($thCheck,$tdCheck){
        var isCheck = false;
        //点击全选,选择所有子元素
        $thCheck.bind("click",function(){
            if(isCheck){
                $tdCheck.prop("checked",!isCheck);
                isCheck = !isCheck;
            }else{
                $tdCheck.prop("checked",!isCheck);
                isCheck = !isCheck;
            }
        })
        //选中所有子元素后,自动勾选全选
        $tdCheck.bind("click",function(){
            $tdCheck.each(function(){
                if($(this).prop("checked")){
                    $thCheck.prop("checked",true);
                    isCheck = true;
                }else{
                    $thCheck.prop("checked",false);
                    isCheck = false;
                    return false;//存在未选中的数据,退出遍历
                }
            })
        })
    }

    使用到的知识点:

    //判断复选框是否被选中,返回值为true表示被选中
    $(ele).prop("checked");
    //设置复选框为选中状态
    $(ele).prop("checked",true);
    //设置复选框为非选中状态
    $(ele).prop("checked",false);
  • 相关阅读:
    centos7 安装prometheus node_exporter
    RMAN备份演练初级篇
    RMAN命令
    oracle数据库的归档模式
    oracle的会话(session)
    oracle的例程
    oracle热备份
    Oracle数据库归档模式的切换及其相关操作详解
    Oracle角色
    类名.class, class.forName(), getClass()区别
  • 原文地址:https://www.cnblogs.com/duanzhenzhen/p/10149075.html
Copyright © 2011-2022 走看看