Resend verification code after jq write code and click 60 seconds

A part .html

 <Div class = "f21"> Get codes </ div>
 
Part two .css // Do not forget to introduce yourself to write css
 .f21{
    height: 36px;
    line-height: 35px;
    width: 125px;
    margin-right: 55px;
    margin-top: 20px;
    background-color: #e5e5e5;
    font-size: 15px;
    border: 1px solid #e5e5e5;
    text-align: center;
    color: #c7000b;
 }
Three. Js part // js library and introduced himself wrote js
var timer="";
was nums = 60;
var validCode = true; // this variable is defined for the subsequent processing is repeated click event
$(".f21").on('click',function(){
            console.log("111");
            var code=$(this);
            if(validCode){
                validCode = false;
                timer=setInterval(function(){
                    if(nums>0){
                        nums--;
                        code.text (nums + "after the second re-transmission");
                        code.addClass("gray-bg");
                    }
                    else{
                        clearInterval(timer);
                        nums = 60; // reset back
                        validCode=true;
                        code.removeClass("gray-bg");
                        code.text ( "send a verification code");
            }
                },1000)
            }
            

        })

Guess you like

Origin www.cnblogs.com/lxc127136/p/12123673.html