ajax按钮倒计时代码

前端之家收集整理的这篇文章主要介绍了ajax按钮倒计时代码前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
  1. var wait = 60;
  2. get_code_time = function (o) {
  3. if (wait == 0) {
  4. o.removeAttribute("disabled");
  5. o.value = "免费获取验证码";
  6. wait = 60;
  7. } else {
  8. o.setAttribute("disabled",true);
  9. o.value = "(" + wait + ")秒后重新获取";
  10. wait--;
  11. setTimeout(function() {
  12. get_code_time(o)
  13. },1000)
  14. }
  15. }

获取手机短信之后调用get_code_time函数代码

//重新获取验证码
$('#codeagain').click(function() {

  1. var o = this;
  2. $.ajax({
  3. url:"Tea_sendCode.action?jsoncallback=?",type:"post",data: {accountId:accountId},dataType: "json",success: function (data) {
  4. if(data.status == 1 && data.code == 200){
  5. alert("验证码已发送至您的手机");
  6. get_code_time(o);
  7. } else {
  8. if(data.msg != ""){
  9. alert(data.msg);
  10. } else {
  11. alert("短信验证码发送失败");
  12. }
  13. }
  14. },error: function (data) {
  15. if(data.status == 0) {
  16. alert(data.msg);
  17. } else {
  18. alert("短信验证码发送失败");
  19. }
  20. }
  21. });

});

猜你在找的Ajax相关文章