html:
<div id="num">
<input class="text-input" type="tel" name="telphone" placeholder="手机号码" οnfοcus='this.value=(this.value=="")?" ":this.value;'
οnblur='this.value=(this.value==" ")?"":this.value.replace(/(^\s*)|(\s*$)/g, "");'
/>
<div class="yan" >发送验证码(60)</div>
</div>
<div id="code">
<input class="text-input" type="tel" name="code" placeholder="验证码" οnfοcus='this.value=(this.value=="")?" ":this.value;'
οnblur='this.value=(this.value==" ")?"":this.value.replace(/(^\s*)|(\s*$)/g, "");'/>
</div>
<div id="next">注册</div>
<div id="xieyi">
如果注册,则表示您已同意<a href="javascript:void(0);" data-toggle="modal" data-target="#myModal">《用户协议书》</a>条款
</div>
<!-- 模态框(Modal) -->
</div>
jq:
//点击发送验证码
$(".yan").click(function(){
var telphone = $("[name = 'telphone']").val();
if(telphone == ""){
alert("请填写手机号码");
return false;
}
//判断该号码是否已被注册
$.get(
"/haslogin/"+telphone,function(data){
if(data.status == 200){
alert("此号码已被注册!");
return false;
}else{
var w = 60;
var dsq;
//发送验证码接口。
$.post(
"/mobsms/sendsms",
{phone:telphone},
function(data){
if(data.status == 467){
alert("请求校验验证码频繁(5分钟校验超过3次)");
return false;
}
if(data.status == 457){
alert("手机格式错误");
return false;
}
if(data.status == 478){
alert("12小时内最多发送5条");
return false;
}
else{
dsq = setInterval(function(){
w--;
$(".yan").html("正在发送("+w+")");
if(w == 0){
w = 60;
clearInterval(dsq);
$(".yan").html("重发(60)");
}
},1000);
}
}
);
}
}
);
});
$('#next').click(function()var telphone = $('[name = "telphone"]').val();
var nick = $('[name = "nikename"]').val();
var pwd = $('[name = "pwd"]').val();
var code = $('[name = "code"]').val();//验证码
if(nick == ''){
alert('请填写昵称!');
return false;
}
if(telphone == ''){
alert('请填写手机号码!');
return false;
}
//判断用户输入的验证码是否正确接口。
$.post(
"/mobsms/checkcode",
{phone:telphone,code:code},
function(data){
if(data.status != 200){
alert("验证码错误或已失效");
return false;
}
}
);
//注册接口
$.post(
'/users/signup',
{login:telphone,nickname:nick,password:pwd},function(data){
if(data.status == 200){
alert('注册成功,马上登录吧!');
}
}
)
}