html5
<input type="text" name="" class="yanzheng " value="" placeholder="请输入验证码"/>
<input type="button" class="text1 q-posit-abs huoquyanzheng q-ziti12" value="获取验证码" onclick="sendemail()" />
JS
var oYanzhengres='';
var countdown=60;
function sendemail(){
var obj = $(".huoquyanzheng");
settime(obj);
console.log('获取验证码11')
//判断验证码输入正确没
$.ajax('',{
data:{
mobile:oShoujihao.val()
},
dataType:'json',//服务器返回json格式数据
type:'post',//HTTP请求类型
timeout:10000,//超时时间设置为10秒;
success:function(res){
console.log(res)
oYanzhengres=res;
},
error:function(xhr,type,errorThrown){
}
});
}
//验证码
function settime(obj){ //发送验证码倒计时
if (countdown == 0){
obj.attr('disabled',false);
//obj.removeattr("disabled");
obj.val("获取验证码");
countdown = 60;
return;
} else {
obj.attr('disabled',true);
obj.val("已发送(" + countdown + ")");
obj.css({'background':'#777','color':'#fff','font-size': '12px','opacity':'.6'})
countdown--;
}
setTimeout(function(){
settime(obj) }
,1000)
}