jquery implementation to get the phone verification code countdown effect

Source: Internet
Author: User

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<script src= "Http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js" ></script>

<body>

<input id= "mobile" type= "text" value= ""/>
<input id= "sendmess" type= "button" value= "Send verification Code"/></p>
</body>

<script type= "Text/javascript" >

$ (function () {

$ ("#sendMess"). Click (function () {
var mobile=$ ("#mobile"). Val ();
if ("!=$.trim (Mobile)") {
Curcount = count;
$ ("#sendMess"). attr ("Disabled", "true");
$ ("#sendMess"). Val ("Please enter the verification code in" + Curcount + "seconds);
Intervalobj = Window.setinterval (setremaintime, 1000); Start Timer, execute once in 1 seconds
/* $.ajax ({
Type: "POST",
URL: "/test/sendmess",
Data:{mobile:mobile},
Success:function (Mess) {
alert (mess);
});
}
});*/
}else{
Alert ("Please enter your phone number!") ")
}

});

});

Timer handler function
function Setremaintime () {
if (Curcount = = 0) {
Window.clearinterval (intervalobj);//Stop Timer
$ ("#sendMess"). Removeattr ("Disabled");//Enable button
$ ("#sendMess"). Val ("Resend Verification Code");
}
else {
curcount--;
$ ("#sendMess"). Val ("Please enter the verification code in" + Curcount + "seconds);
}
}
</script>

jquery implementation to get the phone verification code countdown effect

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.