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

时间:2023-02-25 23:25:44
/* 全选 */
    $("#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>