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.
setTimeout(showT(t-1),5000)
Solution:
setTimeout(function(){showT(t-1)},1000)
Or:
setTimeout("Talert(i)",5000);
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="获取验证码"/>
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) //$('.sjyzm-btn').attr("disabled",true); }else{ $(".sjyzm-btn").val("短信验证"); //$(".sjyzm-btn").removeAttr("disabled"); } }
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!