验证码

var MessageCode = {
sendPhoneCode: function(phone, btn, errorwrap) {
var self = this;
btn.addClass('disabled');
$.ajax({
type: 'POST',
url: 'xxx',
data: { phone: phone, type:1, isReg:2},
success: function(r) {
r = typeof(r) == 'string' ? JSON.parse(r) : r;
if(r.status=="SUCCESS"){
self.showTimer(btn);
}else{
btn.removeClass('disabled').text('获取验证码');
errorwrap.html(r.data.msg).show();
}
},
error: function(){
myUtil.showTip('系统错误');
btn.removeClass('disabled');
}
});
},
showTimer: function(btn){
var self = this;
var v = parseInt(btn.data('time')) || 59;
btn.text(v + 's后重新获取').data('time', v);
self.timer = setInterval(function() {
if (v == 0) {
clearInterval(self.timer);
btn.removeClass('disabled').text('获取验证码');
} else {
btn.text(--v + 's后重新获取').data('time', v);
}
}, 1000);
}
};

你可能感兴趣的:(验证码)