|
// JavaScript Document
//var _widht = document.documentElement.clientWidth; //屏幕宽
var _height = document.documentElement.clientHeight; //屏幕高
//var boxWidth = $(".registerbox").width();
var boxHeight = $(".registerbox").height();
$(".registerbox").css({
top: "80px"
});
/**复选框**/
// $('.agreeNotice').click(function(){
// var formbox = $(this).closest("form");
// if(formbox.find('.gree').prop('checked')){
// formbox.find('.agreeNotice em').css('background-position','0px 0px');
// formbox.find('.gree').prop('checked',false);
// formbox.find('.agreeNotice').next('span').show();
// }else{
// formbox.find('.gree').prop('checked',true);
// formbox.find('.agreeNotice').next('span').hide();
// formbox.find('.agreeNotice em').css('background-position','0px -12px');
//
// }
// });
//手机、邮箱切换
$(".phone").click(function() {
$(this).find("img").attr("src", "images/phoneIcon2.png");
$(".mail").find("img").attr("src", "images/mailIcon.png");
$(".mail").removeClass("active");
$(this).addClass("active");
$(".styleline").animate({
left: "0px"
});
$("#mail_form").hide();
$('#phone_form').show();
});
$(".mail").click(function() {
$(this).find("img").attr("src", "images/mailIcon2.png");
$(".phone").find("img").attr("src", "images/phoneIcon.png");
$(".phone").removeClass("active");
$(this).addClass("active");
$(".styleline").animate({
left: "121px"
});
$("#phone_form").hide();
$("#mail_form").show();
});
//手机注册模块
//验证手机号
var phonePass = false;
function phoneVal() {
var phone = $("#lp_phone").val();
$.ajax("/ajax/isReg?key=" + phone, {
type: "GET",
async: true,
success: function($data) {
if(phone.length == 0) {
$(".msgphone1").text("请输入您的手机号码");
} else {
var hunPhone = /^1[3|4|5|7|8]\d{9}$/;
if(hunPhone.test(phone.trim())) {
if($data.data == false) {
$(".msgphone1").text("您的手机已被注册");
} else {
$(".msgphone1").text("");
phonePass = true;
addEvent(btn, "click", handler); //手机必须验证正确,才执行
}
} else {
phonePass = false;
$(".msgphone1").text("手机格式有误,请输入正确的手机号码");
}
}
},
error: function() {
$.MsgBox.Alert('消息', '服务器请求失败')
},
});
}
$("#lp_phone").blur(function() {
phoneVal();
});
//验证随机验证码
var phoneCode = false;
$("#lp_yzm").blur(function() {
var authCode = $("#lp_yzm").val();
if(authCode.length == 0) {
$(".msgphone2").text("请输入您的验证码");
phoneCode = false;
} else {
var d = /^[0-9a-zA-Z]{4}$/;
if(d.test(authCode.trim())) {
$(".msgphone2").text("");
phoneCode = true;
} else {
$(".msgphone2").text("请输入您的验证码不正确");
phoneCode = false;
}
}
});
//获取手机验证码
//var setTime;
//$(".getcode1").click(function(){
// $(".coderli span").removeClass("getcode1").addClass("getcode2");
// setTime=setInterval(Countdown,1000);
// phoneVerificationCode();
//})
//var j=180;
//function Countdown(){
// j--;
// $(".getcode2").text("等待"+j+"秒后重新获取");
// if(j==0){
// $(".coderli span").removeClass("getcode2").addClass("getcode1").text("请重新获取验证码");
// clearInterval(setTime);
// j=180;
// }
//}
//手机发送验证码
var btn = document.getElementById("getcode");
var handler = function() {
doClick();
phoneVerificationCode(); //调用发送手机验证码接口
removeEvent(btn, 'click', handler); //取消绑定该事件
}
function addEvent(obj, type, handler) {
if(obj.addEventListener) {
obj.addEventListener(type, handler, false);
} else if(obj.attachEvent) {
obj.attachEvent('on' + type, handler);
}
}
function removeEvent(obj, type, handler) {
if(obj.removeEventListener) {
obj.removeEventListener(type, handler, false);
} else if(obj.detachEvent) {
obj.detachEvent("on" + type, handler);
}
}
function doClick() {
removeClass(btn, 'getcodeon');
addClass(btn, 'getcodeoff');
btn.innerHTML = "60s后重新获取";
var clickTime = new Date().getTime();
var Timer = setInterval(function() {
var nowTime = new Date().getTime();
var second = Math.ceil(60 - (nowTime - clickTime) / 1000);
if(second > 0) {
btn.innerHTML = second + "s后重新获取";
} else {
clearInterval(Timer);
removeClass(btn, 'getcodeoff');
addClass(btn, 'getcodeon');
btn.innerHTML = "免费获取验证码";
addEvent(btn, "click", handler);
}
}, 1000);
}
function hasClass(obj, cls) {
return obj.className.match(new RegExp('(\\s|^)' + cls + '(\\s|$)'));
}
function addClass(obj, cls) {
if(!hasClass(obj, cls)) obj.className += " " + cls;
}
function removeClass(obj, cls) {
if(hasClass(obj, cls)) {
var reg = new RegExp('(\\s|^)' + cls + '(\\s|$)');
obj.className = obj.className.replace(reg, ' ');
}
}
//手机发送验证码结束
var state;
function phoneVerificationCode() {
if(phonePass) {
$.ajax("/ajax/regmobilephone", {
type: "get",
async: true,
success: function(data) {
if(data.success) {
state = data.data;
}
},
error: function() {
$.MsgBox.Alert('message', 'fail')
},
data: {
"mobilePhone": $("#lp_phone").val()
},
dataType: 'json'
});
}
};
//验证手机验证码
var setpass1 = false;
function setPhoneCode() {
var pass = $("#lp_coder").val();
if(pass.length == 0) {
$(".msgphone3").text("请输入您的验证码");
} else {
var hunPhone = /^[0-9]{4}$/;
if(hunPhone.test(pass.trim())) {
$(".msgphone3").text("");
setpass1 = true;
} else {
$(".msgphone3").text("验证码4位");
}
}
}
$("#lp_coder").blur(function() {
setPhoneCode();
});
//设置密码
var password;
var setpass = false;
function setPassword() {
password = $("#phone_password").val();
if(password.length == 0) {
$(".msgphone4").text("请输入您的密码");
} else {
var hunPhone = /^[0-9a-zA-Z]{6,}$/;
if(hunPhone.test(password.trim())) {
$(".msgphone4").text("");
setpass = true;
} else {
//$(".msgphone4").text("密码6到16位");
$(".msgphone4").text("密码由6-24 个字符组成,区分大小写");
}
}
}
$("#phone_password").blur(function() {
setPassword();
});
//再次确定密码
var setpassagain = false;
function setPasswordAgain() {
var passwordAgain = $("#phone_password2").val();
if(passwordAgain.length == 0) {
$(".msgphone5").text("请再次输入您的密码");
} else {
var hunPhone = /^[0-9a-zA-Z]{6,}$/;
if(hunPhone.test(password.trim()) && passwordAgain == password) {
$(".msgphone5").text("");
setpassagain = true;
} else {
$(".msgphone5").text("密码错误");
}
}
}
$("#phone_password2").blur(function() {
setPasswordAgain();
});
//手机注册提交
$("#btnn").click(function() {
if(phonePass && setpass1 && setpassagain) {
$.ajax("/ajax/regmobile", {
type: "POST",
async: false,
success: function(data) {
if(data.success) {
loginagain(); //调用登录的接口
// $(".completedcover").css("display","block");
// $("#afterSay").click(function(){
// location.href="index.html";
// });
// $("#todayPerfect").click(function(){
// location.href="information-add.html?id="+data.data;
// });
location.href = "information-add.html?id=" + data.data;
}
},
error: function() {
$.MsgBox.Alert('message', 'fail')
},
data: {
"state": state,
"mobilePhone": $("#lp_phone").val(),
"validateCode": $("#lp_coder").val(),
"password": $("#phone_password").val(),
"inviterId": GetQueryString("inviterId")
},
dataType: 'json'
});
}else{
$(".msgphone1").text("请输入您的手机号码");
$(".msgphone3").text("请输入您的验证码");
$(".msgphone4").text("请输入您的密码");
$(".msgphone5").text("请再次输入您的密码");
}
});
function loginagain() {
$.ajax("/ajax/login", {
type: "POST",
async: false,
success: function(data) {},
error: function() {
$.MsgBox.Alert('message', 'fail')
},
data: {
"pw": $("#phone_password").val(),
"lk": $("#lp_phone").val()
},
dataType: 'json'
});
}
//邮箱注册模块
//邮箱验证
var emailPass = false;
function valEmail() {
var email = $("#lp_email").val();
//var gunf=/^\w+@\w+\.((cn)|(com)|(com\.cn))$/;
var gunf = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
$.ajax("/ajax/isReg?key=" + email, {
type: "GET",
async: true,
success: function($data) {
if($data.data == false) {
$(".msgema1 span").text("您的邮箱已被注册");
} else {
if(gunf.test(email.trim())) {
$(".msgema1 span").text("");
emailPass = true;
} else {
/*alert("请输入正确是邮箱地址");*/
$(".msgema1 span").text("请输入正确是邮箱地址");
emailPass = false;
}
}
},
error: function() {
$.MsgBox.Alert('消息', '服务器请求失败')
},
});
}
$("#lp_email").blur(function() {
valEmail();
});
//输入密码及确认密码
var oldPass = false;
var isPass = false;
function valOld() {
var oldPassword = $("#mail_password").val();
if(oldPassword.length == 0) {
$(".msgema2 span").text("密码不能为空");
oldPass = false;
} else if(oldPassword.length < 6) {
$(".msgema2 span").text("密码不少于6位,请输入正确的密码");
} else {
$(".msgema2 span").text("");
oldPass = true;
}
}
$("#mail_password").blur(function() {
valOld();
})
function valNew() {
var newPassword = $("#mail_password").val();
var oldPassword = $("#mail_password1").val();
if(oldPassword.length == 0) {
$(".msgema3 span").text("密码不能为空");
} else if(oldPassword.length < 6) {
$(".msgema3 span").text("密码长度过短,至少六位");
} else if(oldPassword != newPassword) {
$(".msgema3 span").text("两次密码不一致");
} else {
isPass = true;
$(".msgema3 span").text("");
}
}
$("#mail_password1").blur(function() {
valNew();
})
//邮箱注册提交
function mailRegistration() {
var mailVal = $("#lp_email").val();
var passwordVal = $("#mail_password1").val();
if(isPass && emailPass) {
$.ajax("/ajax/regmail", {
type: "POST",
async: false,
success: function(data) {
if(data.success) {
$.cookie('mailVal', mailVal);
location.href = "bind-mail.html";
} else {
$.MsgBox.Alert('消息', '邮箱发送失败');
}
},
error: function() {
$.MsgBox.Alert('消息', '邮箱发送失败');
},
data: {
"mail": mailVal,
"password": passwordVal,
"inviterId": GetQueryString("inviterId")
},
dataType: 'json'
});
}else{
$(".msgema1 span").text("请输入正确是邮箱地址");
$(".msgema2 span").text("密码不能为空");
$(".msgema3 span").text("密码不能为空");
}
}
$("#btnn1").click(function() {
mailRegistration();
});
|