[JavaScript] 发验证码倒计时 →→→→→进入此内容的聊天室

来自 , 2019-04-30, 写在 JavaScript, 查看 128 次.
URL http://www.code666.cn/view/8068fee5
  1. var wait=60;
  2. function time(o) {
  3.         if (wait == 0) {
  4.                 $('#btn_yzm').removeAttr("disabled");
  5.                 $('#btn_yzm').val("获取验证码");
  6.                 wait = 60;
  7.         } else {
  8.                 //o.setAttribute("disabled", true);
  9.                 $('#btn_yzm').attr("disabled", true);
  10.                 $('#btn_yzm').val("重新发送(" + wait + ")");
  11.                  
  12.                 wait--;
  13.                 setTimeout(function() {
  14.                 time(o)
  15.                 },
  16.                 1000)
  17.         }
  18. }
  19.  
  20.  function checkMobile(sMobile){
  21.     if(!(/^1[3|4|5|8|7][0-9]\d{4,8}$/.test(sMobile))){
  22.         return false;
  23.     }
  24.         return true;   
  25. }
  26. document.getElementById("btn_yzm").onclick=function(){
  27.         if($("#mobile").val() == ''){
  28.                 alert("请输入手机号");
  29.                 return false;
  30.         }
  31.         if(!checkMobile($("#mobile").val()){
  32.                 alert("请输入您的手机号码!");
  33.                 return false;
  34.         }
  35.        
  36.         $.ajax({
  37.            type: "POST",
  38.            url: "<?php echo $this->createUrl('user/yzm')?>",
  39.            data: "y=1&sj="+$('#mobile').val(),
  40.            success: function(msg){
  41.            console.log(msg);
  42.                        
  43.                   if(msg  == '短信发送成功'){
  44.                        
  45.                         alert("发送验证码成功");
  46.                         time(this);
  47.                   }else{
  48.                         alert("发送验证码失败 --" + msg);
  49.                         return false;
  50.                   }
  51.            }
  52.         });
  53.  
  54.  
  55.  
  56. }

回复 "发验证码倒计时"

这儿你可以回复上面这条便签

captcha