登录页面发送验证码倒计时功能

要引入jquery的
以下是html页面

<!DOCTYPE html>
<html>
  <head>
    <title>后台管理登录 - Powered by {:config('hisiphp.name')}</title>
    <meta http-equiv="Access-Control-Allow-Origin" content="*" />
    <meta name="renderer" content="webkit" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta
      name="viewport"
      content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0"
    />
    <link rel="stylesheet" href="__PUBLIC_JS__/layui/css/layui.css" />
    <style type="text/css">
      body {
        margin: 0;
        padding: 0;
        font-family: PingFangSC-Regular, PingFang SC;
      }
      .logindl {
        position: relative;
        width: 100vw;
        height: 100vh;
        background: #00f;
      }
      .logintitle {
        position: absolute;
        top: 0;
        left: 0;
        display: flex;
        align-items: center;
        padding-left: 2.917rem;
        width: 100%;
        height: 3.865rem;
        background: #ffffff;
        box-shadow: 0rem 0rem 0.573rem 0rem rgba(73, 128, 255, 0.16);
      }
      .logintitle img {
        margin-right: 0.99rem;
        width: 2.156rem;
        height: 2.156rem;
      }
      .logintitle span {
        font-size: 1.042rem;
        font-weight: 400;
        color: #333333;
      }
      .centerinfo {
        position: absolute;
        top: 45%;
        left: 50%;
        transform: translate(-50%, -50%);
        background: #ffffff;
        border-radius: 0.729rem;
        padding: 2rem 4.479rem 1.546rem 4.479rem;
      }
      .centerinfo #tab_bar ul {
        display: flex;
        justify-content: space-between;
        padding: 0 2.042rem;
      }
      .centerinfo #tab_bar ul li {
        list-style: none;
        font-size: 1.15rem;
        font-weight: 500;
        color: #666666;
      }
      #tab1_content,
      #tab2_content {
        margin: 2.2rem -1rem 0 -1rem;
      }
      #tab1_content .phonenum input,
      #tab2_content .zhlogin input,
      #tab2_content .pwlogin input {
        border-radius: 2.604rem;
        border: 0.052rem solid #afafaf;
        padding: 0.842rem 1.467rem;
        width: 19rem;
        height: 1.279rem;
        font-size: 1.042rem;
        font-weight: 400;
        color: #666666;
      }
      #tab1_content .yzm,
      #tab2_content .yzmlogin {
        display: flex;
        align-items: center;
        margin-top: 1.2rem;
      }
      #tab1_content .yzm #yzm {
        border-radius: 2.604rem;
        border: 0.052rem solid #afafaf;
        padding: 0.842rem 1.467rem;
        width: 11rem;
        height: 1.279rem;
        margin-right: 1.363rem;
        font-size: 1.042rem;
        font-weight: 400;
        color: #666666;
      }
      #tab1_content .yzm #fsyzm {
        font-size: 1.042rem;
        font-weight: 400;
        color: #4980ff;
        background: none;
        border: none;
      }
      #tab2_content .yzmlogin {
        width: 22.5rem;
        display: flex;
        align-items: center;
      }
      #tab2_content .yzmlogin input {
        border-radius: 2.604rem;
        border: 0.052rem solid #afafaf;
        padding: 0.842rem 1.467rem;
        width: 9.66rem;
        height: 1.279rem;
        margin-right: 1.863rem;
        font-size: 1.042rem;
        font-weight: 400;
        color: #666666;
      }
      #tab2_content .yzmlogin div {
        width: 7rem;
        height: 2.7rem;
        background: #000;
      }
      .dlbtn,
      .btnlogin {
        margin-top: 2.438rem;
        width: 22rem;
        height: 3.2rem;
        background: #4980ff;
        border-radius: 2.771rem;
        display: flex;
        justify-content: center;
        align-items: center;

        font-size: 1.15rem;
        font-weight: 500;
        color: #ffffff;
      }

      #tab2_content .zhlogin,
      #tab2_content .pwlogin {
        margin-top: 1.2rem;
      }
    </style>
  </head>
  <body>
    <div class="logindl">
      <div class="logintitle">
        <img src="./logo.png" alt="" />
        <span>心耘后台管理中心</span>
      </div>

      <div class="centerinfo">
        <div id="tab_bar">
          <ul>
            <li id="tab1" onclick="myclick(1)" style="color: #407efd">
              手机号登录
            </li>
            <li id="tab2" onclick="myclick(2)">账号登录</li>
          </ul>
        </div>

        <div class="tab_css" id="tab1_content" style="display: block">
          <div class="phonenum">
            <input type="number" name="" id="" placeholder="手机号" />
          </div>
          <div class="yzm">
            <input type="text" name="" id="yzm" placeholder="验证码" />
            <input
              type="button"
              name=""
              id="fsyzm"
              onclick="sendCode(this)"
              value="发送验证码"
            />
          </div>

          <div class="dlbtn">登录</div>
        </div>

        <div class="tab_css" id="tab2_content" style="display: none">
          <div class="zhlogin">
            <input type="text" name="" id="" placeholder="账号" />
          </div>
          <div class="pwlogin">
            <input type="number" name="" id="" placeholder="密码" />
          </div>
          <div class="yzmlogin">
            <input type="text" name="" id="" placeholder="验证码" />
            <div>验证码</div>
          </div>

          <div class="btnlogin">登录</div>
        </div>
      </div>
    </div>

    <script src="./jquery.js"></script>
    <script>
      //手机号登录和账号登录切换
      var myclick = function (v) {
        var lis = document.getElementsByTagName("li");
        for (var i = 0; i < lis.length; i++) {
          var li = lis[i];
          if (li == document.getElementById("tab" + v)) {
            li.style.color = "#407EFD";
          } else {
            li.style.color = "#666666";
          }
        }
        var divs = document.getElementsByClassName("tab_css");
        for (var i = 0; i < divs.length; i++) {
          var div = divs[i];
          if (div == document.getElementById("tab" + v + "_content")) {
            div.style.display = "block";
          } else {
            div.style.display = "none";
          }
        }
      };
      //发送验证码倒计时
      var clock = "",
        nums = 30;
      var btn;
      function sendCode(thisBtn) {
        btn = thisBtn;
        btn.disabled = true; //将按钮置为不可点击
        btn.value = "倒计时 " + nums + " 秒";
        clock = setInterval(doLoop, 1000); //一秒执行一次
      }
      function doLoop() {
        nums--;
        if (nums > 0) {
          btn.value = "倒计时 " + nums + " 秒";
        } else {
          clearInterval(clock); //清除js定时器
          btn.disabled = false;
          btn.value = "发送验证码";
          nums = 30; //重置时间
        }
      }
    </script>
  </body>
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
好的,以下是一个简单的示例代码,可以使用jQuery发送验证码倒计时60秒: HTML: ```html <input type="text" id="phone" placeholder="请输入手机号码"/> <button id="send-code">获取验证码</button> ``` JavaScript: ```javascript $(document).ready(function() { var count = 60; //倒计时初始值 var countdownTimer; //倒计时定时器 // 点击“获取验证码”按钮 $("#send-code").click(function() { var phone = $("#phone").val(); if (phone == "") { alert("请输入手机号码"); return; } // 发送验证码的逻辑 $.ajax({ url: "send_code.php", type: "POST", data: { phone: phone }, success: function(response) { if (response == "success") { // 发送成功,开始倒计时 startCountdown(); } else { alert("发送失败,请稍后重试"); } }, error: function() { alert("发送失败,请稍后重试"); } }); }); // 开始倒计时 function startCountdown() { count = 60; $("#send-code").prop("disabled", true); countdownTimer = setInterval(function() { count--; if (count <= 0) { clearInterval(countdownTimer); $("#send-code").prop("disabled", false).html("获取验证码"); } else { $("#send-code").html("重新发送(" + count + ")"); } }, 1000); } }); ``` 这段代码将会在用户点击“获取验证码”按钮之后,发送一个 AJAX 请求到 `send_code.php` 页面,然后开始倒计时60秒。在倒计时期间,按钮会显示当前倒计时的秒数,直到倒计时结束。如果用户在倒计时期间再次点击“获取验证码”按钮,该按钮将会被禁用,直到倒计时结束。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

钟Bubble

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值