Home > Web Front-end > JS Tutorial > Solution to the problem of invalid JS setting time

Solution to the problem of invalid JS setting time

高洛峰
Release: 2017-02-20 16:47:26
Original
1579 people have browsed it

When sending a short message verification code, you need to use js to set the time reverse order. Sometimes it will cause js failure. What should I do? Today, the editor will share with you the solution to the problem of invalid JS setting time. Friends who need it can refer to it

When sending SMS verification codes, you need to use js setting time in reverse order: Sometimes this conventional writing method It will cause js to fail. I tried many methods to find the problem. It may be because the js version is too low.

Solution to the problem of invalid JS setting time

setTimeout(showT(t-1),5000)
Copy after login

Solution:

setTimeout(function(){showT(t-1)},1000)
Copy after login

Or:

setTimeout("Talert(i)",5000);
Copy after login

jquery code: The value must be set with input in order to use jquery to change the value

<<input type="button" id="sjyzm-btn" class="sjyzm-btn" value="获取验证码"/>
Copy after login

 var t = 120;
   showT(t);
  function showT(t) {
    if(t > 0){
     $(".sjyzm-btn").val(t +"秒");
     setTimeout(function(){showT(t-1)},1000)
     //setTimeout(showT(t-1),5000)
     //$(&#39;.sjyzm-btn&#39;).attr("disabled",true);
     }else{
     $(".sjyzm-btn").val("短信验证");
     //$(".sjyzm-btn").removeAttr("disabled");
    }
   }
Copy after login

The above is the solution to the problem of invalid JS setting time introduced by the editor. I hope it is helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank you all for your support of the PHP Chinese website!

For more articles related to solutions to the problem of invalid JS setting time, please pay attention to the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template