html给手机发送验证码案例,js实现手机发送验证码功能

效果图:

0d72a8941259d26cd4a40b62468634e7.png

代码如下:

发送验证码倒计时功能

@charset "utf-8";

*{ margin:0; padding:0; list-style:none}

body{ background:#EBECED; font-family:'微软雅黑'}

.form{width: 450px;height: auto; margin:100px auto; overflow:hidden;font-size: 16px;color: #1b1b1b;text-align: left; padding:50px; border:1px solid #ccc; border-radius:10px;}

.form div{padding:5px 0;overflow: hidden;}

.form label{width: 90px;display: block;float: left;}

.form .infos{width:200px;height: 26px;line-height: 26px;border:1px solid #BFBFBF;padding:2px;border-radius:4px;float: left;}

.form .div-phone a.send1{height: 26px;text-decoration:none;line-height: 26px;padding:2px;width: 80px;background: #AA8926;font-family: '宋体';color: #fff;font-size: 12px;text-align: center;display: block;float: left;border-radius:2px;margin-left:2px;-webkit-transition:all 0.2s linear;-moz-transition:all 0.2s linear;-ms-transition:all 0.2s linear;-o-transition:all 0.2s linear;transition:all 0.2s linear;}

.form .div-phone a.send1:hover{text-decoration: none;background: #866c1b;-webkit-transition:all 0.2s linear;-moz-transition:all 0.2s linear;-ms-transition:all 0.2s linear;-o-transition:all 0.2s linear;transition:all 0.2s linear;}

.form .div-phone a.send0{height: 26px;text-decoration:none;line-height: 26px;padding:2px;width: 80px;background: #A1A1A1;font-family: '宋体';color: #fff;font-size: 12px;text-align: center;display: block;float: left;border-radius:2px;margin-left:2px;}

.form .div-phone a.send0:hover{background: #A1A1A1;font-family: '宋体';color: #fff;font-size: 12px;text-decoration: none;}

.form span.error{height: 26px;line-height: 26px;padding:2px;width: 100px;color: red;padding-left:20px;display: block;float: left;margin-left:10px;font-size: 12px;font-family: '宋体';background: url(../images/error.png) no-repeat left center;}

.form #phone{width: 116px;}

.form .div-conform{padding-right:153px;}

.form .div-conform a.conform{width: 136px;height: 34px;display: block;text-align: left;overflow: hidden;background: url(../images/btn.jpg) no-repeat;float: right;text-indent: -1000px;}

用户名

验证码

var sends = {

checked:1,

send:function(){

var numbers = /^1\d{10}$/;

var val = $('#phone').val().replace(/\s+/g,""); //获取输入手机号码

if($('.div-phone').find('span').length == 0 && $('.div-phone a').attr('class') == 'send1'){

if(!numbers.test(val) || val.length ==0){

$('.div-phone').append('手机格式错误');

return false;

}

}

if(numbers.test(val)){

var time = 30;

$('.div-phone span').remove();

function timeCountDown(){

if(time==0){

clearInterval(timer);

$('.div-phone a').addClass('send1').removeClass('send0').html("发送验证码");

sends.checked = 1;

return true;

}

$('.div-phone a').html(time+"S后再次发送");

time--;

return false;

sends.checked = 0;

}

$('.div-phone a').addClass('send0').removeClass('send1');

timeCountDown();

var timer = setInterval(timeCountDown,1000);

}

}

}

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持脚本之家!

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值