Js-Html 前端系列--全选,反选

本文介绍了一种使用JavaScript实现全选与反选功能的方法,并附带了一个计时器示例。通过jQuery的选择器和属性操作实现了对多个复选框的状态控制。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

/* 全选 */
    $("#selectedAll").click(function(){
        var boxcList = $(".boxc");var boxcList1 = $(".boxcp");
        var c = $(this).attr("checked");
        if(c == "undefined"||c == undefined||c == false){
            boxcList.prop("checked",true);
            boxcList.attr("checked",true);
            boxcList1.prop("checked",true);
            boxcList1.attr("checked",true);
            $(this).prop("checked",true);
            $(this).attr("checked",true);
        }else{
            boxcList.removeAttr("checked");
            boxcList1.removeAttr("checked");
            $(this).removeAttr("checked");
        }


    });
    /* 反选 */
    $("#backselectedAll").click(function(){
        var boxcList = $(".boxc");var boxcList1 = $(".boxcp");
        for(var i=0;i<boxcList.length;i++){
            var c = boxcList.eq(i).attr("checked");
            if(c == "undefined"||c == undefined||c == false){
                boxcList.eq(i).prop("checked",true);
                boxcList.eq(i).attr("checked",true);
            }else{
                boxcList.eq(i).removeAttr("checked");
            }
        }
        for(var i=0;i<boxcList1.length;i++){
            var c = boxcList1.eq(i).attr("checked");
            if(c == "undefined"||c == undefined||c == false){
                boxcList1.eq(i).prop("checked",true);
                boxcList1.eq(i).attr("checked",true);
            }else{
                boxcList1.eq(i).removeAttr("checked");
            }
        } 
    });

Js产生两个首尾相连的记时器

<script>
var time=0;
 setTimeout(a(), 1000);
 alert("开始")
 function b(){
     alert("么么哒 "+time++)
     setTimeout(a(), 5000); 
 }
 function a(){
     alert("萌萌哒 "+time++)
     setTimeout(b(), 5000); 
 }
</script>

转载于:https://www.cnblogs.com/ChickenTang/p/5655400.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值