验证码倒计时发送

主要使用到JS的:
1、disabled=true|false;
disabled的属性设置或返回是否禁用单选按钮。true为禁用。
如果想取消时使用:
document.getElementById(“text_id”).disabled=”false”;不会起作用。
正确写法为:document.getElementById(“text_id”).disabled=false;去掉引号或者:document.getElementById(“text_id”).disabled=”“;设置为空即可。
2、removeAttribute(‘disabled’);
移除/删除指定的属性。
removeProperty与removeAttribute的区别是:
removeProperty:符合w3c的(gecko,opera,webkit)的使用
removeAttribute:IE的使用

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>验证码倒计时发送</title>
    <script type="text/javascript">
    window.onload=function(){
        var send=document.getElementById('send'),
            times=5,//倒计时时间
            timer=null;
        send.onclick=function(){
          // 计时开始 
          timer=setInterval(function (){
            send.value=times+"秒后重试";
            times--;
            send.disabled=true;//让input标签不可用
            if(times<0){
                clearInterval(timer);
                send.value="发送验证码";
                times=5;
                send.removeAttribute('disabled');//移除disabled属性
            }
          }, 1000);
      }
        }
    </script>
</head>
<body>
    <input type="button" id="send" value="发送验证码">
</body>
</html>

查看效果

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值