JS for 60 seconds Countdown effect (using jquery)

Source: Internet
Author: User

Today met to achieve a similar kind of SMS verification code 60 Seconds Countdown Demand, long time not to write JS, a little rusty. Record the code to facilitate follow-up inspection. Here I used the Jquey, after all, it is simple to write. Look directly at the effects and code below. First, the effect                                                                           Two, code (1) HTML
 
   
  
  1. <input type="button" id="btn" value="免费获取验证码" onclick="daojishi(10,this)" />
Attention:to introduce jquery

(2) JS
  
 
  1. <script type="text/javascript">
  2. function daojishi(seconds,obj){
  3. if (seconds > 1){
  4. seconds--;
  5. $(obj).val(seconds+"秒后可重新获取 ").attr("disabled", true);//禁用按钮
  6. // 定时1秒调用一次
  7. setTimeout(function(){
  8. daojishi(seconds,obj);
  9. },1000);
  10. }else{
  11. $(obj).val("免费获取验证码").attr("disabled", false);//启用按钮
  12. }
  13. }
  14. </script>

JS for 60 seconds Countdown effect (using jquery)

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.