jhy-ocean

验证码防止用户重复点击


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
        手机号:<input type="text" name=\'cell\'>
        <button>获取验证码</button>
        <input type="submit" value="提交">
</body>
</html>
<script>
//当用户获取手机验证码后 不能重复获取 js部分
    var des = document.querySelector(\'button\');
    des.onclick=function(){
        var a = 90;
        var but = document.querySelector(\'button\');
        if(a==90 || a==0){
            // 当a存在0结束 90开始时可以点击
            setInterval(function(){
              a--;
              console.log(a);
              but.innerText=a;
              // 把倒计时追加到标签内容
            },1000)
            // 添加属性禁止点击
            but.setAttribute( "disabled","true");
        }else{
            //当定时器倒计时跑完时 可以点击
            but.setAttribute( "disabled","");
        }
    }
</script>

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-13
  • 2021-12-09
  • 2022-12-23
  • 2022-02-13
猜你喜欢
  • 2021-06-15
  • 2021-07-26
  • 2021-12-15
  • 2022-12-23
  • 2023-01-30
  • 2021-11-17
相关资源
相似解决方案