jquery implementation of the Click button after the countdown effect, more for the implementation of mobile phone verification Code, email Verification Code

Source: Internet
Author: User

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

<title></title>
<script src= "Html/js/jquery-1.4.1.min.js" type= "Text/javascript" ></script>
<script type= "Text/javascript" >

/*-------------------------------------------*/
var intervalobj; Timer variable, control time
var count = 5; Interval function, 1 second execution
var curcount;//current number of seconds remaining
var code = ""; Verification Code
var codelength = 6;//Verification Code length
function SendMessage () {
Curcount = count;
var Dealtype; Authentication method
var uid=$ ("#uid"). Val ();//user UID
if ($ ("#phone"). attr ("checked") = = True) {
Dealtype = "Phone";
}
else {
Dealtype = "email";
}
Generate Verification Code
for (var i = 0; i < codelength; i++) {
Code + = parseint (Math.random () * 9). toString ();
}
Set button effect to start timing
$ ("#btnSendCode"). attr ("Disabled", "true");
$ ("#btnSendCode"). Val ("Please enter the verification code in" + Curcount + "seconds);
Intervalobj = Window.setinterval (setremaintime, 1000); Start Timer, execute once in 1 seconds
Send processing data to the background
$.ajax ({
Type: "POST",//Transmit by post
DataType: "Text",//Data format: JSON
URL: ' login.ashx ',//Destination address
Data: "dealtype=" + Dealtype + "&uid=" + uid + "&code=" + code,
Error:function (XMLHttpRequest, Textstatus, Errorthrown) {},
Success:function (msg) {}
});
}
Timer handler function
function Setremaintime () {
if (Curcount = = 0) {
Window.clearinterval (intervalobj);//Stop Timer
$ ("#btnSendCode"). Removeattr ("Disabled");//Enable button
$ ("#btnSendCode"). Val ("Resend Verification Code");
Code = ""; Clear the Verification code. If you do not clear, after the time, the input received the verification code is still valid
}
else {
curcount--;
$ ("#btnSendCode"). Val ("Please enter the verification code in" + Curcount + "seconds);
}
}
</script>
<body>
<input id= "Btnsendcode" type= "button" value= "Send verification Code" onclick= "SendMessage ()"/></p>
</body>

jquery implementation of the Click button after the countdown effect, more for the implementation of mobile phone verification Code, email Verification Code

Related Article

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.