jquery Counts Down 60 Seconds to Send Mail
Published: 2019-05-15
 <script type="text/javascript">
                var i = 120;
                $('#btn').click(function(){
                  var url = "{{url('send')}}";
                  var email = $('#empty').val();
                 /* alert(email);
                  alert(url);*/
                  if (email=='') {
                    alert('请填写邮箱');
                  };
                  $.get(url,{'email':email},function(msg)
                  {
                    //alert(msg);
                      if (msg==0) {
                          function wait()
                               {
                          if (i > 0)
                              {
                              i--;
                              $('#btn').attr("disabled", true);
                              $('#btn').val("重新发送(" + i + ")");
                              }else{
                                $('#btn').attr("disabled");
                                $('#btn').val("免费获取验证码");
                                i= 120;
                                alert('验证码失效')
                              }
                          }
                         setInterval(wait, 1000);
                      }else{
                           alert('发送失败');
                      }
                  })
                })
                
            </script>
 <td>输入验证码:</td><td><input type="text" name="empty"><input type="button" id="btn" value="免费获取验证码" class="empty"/>
 <script type="text/javascript">
                var i = 120;
                $('#btn').click(function(){
                  var url = "{{url('send')}}";
                  var email = $('#empty').val();
                 /* alert(email);
                  alert(url);*/
                  if (email=='') {
                    alert('请填写邮箱');
                  };
                  $.get(url,{'email':email},function(msg)
                  {
                    //alert(msg);
                      if (msg==0) {
                          function wait()
                               {
                          if (i > 0)
                              {
                              i--;
                              $('#btn').attr("disabled", true);
                              $('#btn').val("重新发送(" + i + ")");
                              }else{
                                $('#btn').attr("disabled");
                                $('#btn').val("免费获取验证码");
                                i= 120;
                                alert('验证码失效')
                              }
                          }
                         setInterval(wait, 1000);
                      }else{
                           alert('发送失败');
                      }
                  })
                })
                
            </script>