JavaScript click on button Countdown effect code

Source: Internet
Author: User

Look at a registration get validation countdown effect


Common examples of obtaining authentication codes on cell phone or email

The code is as follows Copy Code


<input type= "button" id= "btn" value= "Free access to authentication code"/>

<script type= "Text/javascript" >
var wait=60;
function Time (o) {
if (wait = = 0) {
O.removeattribute ("Disabled");
O.value= "Free access to verification code";
wait = 60;
} else {
O.setattribute ("Disabled", true);
O.value= "Resend (" + Wait + ")";
wait--;
settimeout (function () {
Time (O)
},
1000)
}
}
document.getElementById ("Btn"). Onclick=function () {time (this);}
</script>

User Registration Countdown Effect

HTML code

The code is as follows Copy Code


<div style= "width:350px; Text-align:center; " >
<form name= "RegForm" method= "POST" action= "" >
<input type= "Submit" value= "please read the terms of service (0)" disabled= "Disabled" id= "REG_BTN" >
<input id= "btnclose" type= "button" value= "I disagree with" onclick= "window.close (); >
</form>
</div>

JS Code

<script language= "JavaScript" >
<!--
var wait_time = 8; Set number of seconds (in seconds)
var secs_time = 0;
for (Var i=1;i<=wait_time;i++)
{
Window.settimeout ("Stimer (" +i+ ")", i*1000);
}
function Stimer (num)
{
if (num==wait_time)
{
document.getElementById ("Reg_btn"). value= "Consent to register";
document.getElementById ("Reg_btn"). Disabled=false;
}
Else
{
Secs_time=wait_time-num;
document.getElementById ("Reg_btn"). value= "Please read the terms of service first (" +secs_time+ ");
}
}
-->
</script>

Friendly tips, this can achieve a false countdown effect if the user refresh the page can be repeatedly clicked, of course, this needs to be in the server program to judge, this is not introduced here.

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.