Brak opisu

register.js 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. // JavaScript Document
  2. //var _widht = document.documentElement.clientWidth; //屏幕宽
  3. var _height = document.documentElement.clientHeight; //屏幕高
  4. //var boxWidth = $(".registerbox").width();
  5. var boxHeight = $(".registerbox").height();
  6. $(".registerbox").css({ top:"40px"});
  7. /**复选框**/
  8. $('.agreeNotice').click(function(){
  9. var formbox = $(this).closest("form");
  10. if(formbox.find('.gree').prop('checked')){
  11. formbox.find('.agreeNotice em').css('background-position','0px 0px');
  12. formbox.find('.gree').prop('checked',false);
  13. formbox.find('.agreeNotice').next('span').show();
  14. }else{
  15. formbox.find('.gree').prop('checked',true);
  16. formbox.find('.agreeNotice').next('span').hide();
  17. formbox.find('.agreeNotice em').css('background-position','0px -12px');
  18. }
  19. });
  20. //手机、邮箱切换
  21. $(".phone").click(function(){
  22. $(this).find("img").attr("src","images/phoneIcon2.png");
  23. $(".mail").find("img").attr("src","images/mailIcon.png");
  24. $(".mail").removeClass("active");
  25. $(this).addClass("active");
  26. $(".styleline").animate({left:"0px"});
  27. $("#mail_form").hide();
  28. $('#phone_form').show();
  29. });
  30. $(".mail").click(function(){
  31. $(this).find("img").attr("src","images/mailIcon2.png");
  32. $(".phone").find("img").attr("src","images/phoneIcon.png");
  33. $(".phone").removeClass("active");
  34. $(this).addClass("active");
  35. $(".styleline").animate({left:"151px"});
  36. $("#phone_form").hide();
  37. $("#mail_form").show();
  38. });
  39. //手机注册模块
  40. //验证手机号
  41. var phonePass = false;
  42. function phoneVal(){
  43. var phone= $("#lp_phone").val();
  44. $.ajax("/ajax/isReg?key="+phone,{
  45. type:"GET",
  46. async: true,
  47. success:function($data){
  48. if(phone.length==0){
  49. $(".msgphone1").text("请输入您的手机号码");
  50. }else{
  51. var hunPhone=/^1[3|4|5|7|8]\d{9}$/;
  52. if(hunPhone.test(phone.trim())){
  53. if($data.data==false){
  54. $(".msgphone1").text("您的手机已被注册");
  55. }else{
  56. $(".msgphone1").text("");
  57. phonePass = true;
  58. addEvent(btn,"click",handler);//手机必须验证正确,才执行
  59. }
  60. }else{
  61. phonePass = false;
  62. $(".msgphone1").text("手机格式正确,请输入正确的手机号码");
  63. }
  64. }
  65. },
  66. error:function(){
  67. $.MsgBox.Alert('消息','服务器请求失败')},
  68. });
  69. }
  70. $("#lp_phone").blur(function(){
  71. phoneVal();
  72. });
  73. //验证随机验证码
  74. var phoneCode=false;
  75. $("#lp_yzm").blur(function(){
  76. var authCode=$("#lp_yzm").val();
  77. if(authCode.length==0){
  78. $(".msgphone2").text("请输入您的验证码");
  79. phoneCode=false;
  80. }else{
  81. var d=/^[0-9a-zA-Z]{4}$/;
  82. if(d.test(authCode.trim())){
  83. $(".msgphone2").text("");
  84. phoneCode=true;
  85. }
  86. else{
  87. $(".msgphone2").text("请输入您的验证码不正确");
  88. phoneCode=false;
  89. }
  90. }
  91. });
  92. //获取手机验证码
  93. //var setTime;
  94. //$(".getcode1").click(function(){
  95. // $(".coderli span").removeClass("getcode1").addClass("getcode2");
  96. // setTime=setInterval(Countdown,1000);
  97. // phoneVerificationCode();
  98. //})
  99. //var j=180;
  100. //function Countdown(){
  101. // j--;
  102. // $(".getcode2").text("等待"+j+"秒后重新获取");
  103. // if(j==0){
  104. // $(".coderli span").removeClass("getcode2").addClass("getcode1").text("请重新获取验证码");
  105. // clearInterval(setTime);
  106. // j=180;
  107. // }
  108. //}
  109. //手机发送验证码
  110. var btn = document.getElementById("getcode");
  111. var handler = function(){
  112. doClick();
  113. phoneVerificationCode();//调用发送手机验证码接口
  114. removeEvent(btn,'click',handler);//取消绑定该事件
  115. }
  116. function addEvent(obj,type,handler){
  117. if(obj.addEventListener){
  118. obj.addEventListener(type,handler,false);
  119. }else if(obj.attachEvent){
  120. obj.attachEvent('on'+type,handler);
  121. }
  122. }
  123. function removeEvent(obj,type,handler){
  124. if(obj.removeEventListener){
  125. obj.removeEventListener(type,handler,false);
  126. }else if(obj.detachEvent){
  127. obj.detachEvent("on"+type,handler);
  128. }
  129. }
  130. function doClick(){
  131. removeClass(btn,'getcodeon');
  132. addClass(btn,'getcodeoff');
  133. btn.innerHTML="120s后重新获取";
  134. var clickTime = new Date().getTime();
  135. var Timer = setInterval(function(){
  136. var nowTime = new Date().getTime();
  137. var second = Math.ceil(120-(nowTime-clickTime)/1000);
  138. if(second>0){
  139. btn.innerHTML = second+"s后重新获取";
  140. }else{
  141. clearInterval(Timer);
  142. removeClass(btn,'getcodeoff');
  143. addClass(btn,'getcodeon');
  144. btn.innerHTML = "免费获取验证码";
  145. addEvent(btn,"click",handler);
  146. }
  147. },1000);
  148. }
  149. function hasClass(obj, cls) {
  150. return obj.className.match(new RegExp('(\\s|^)' + cls + '(\\s|$)'));
  151. }
  152. function addClass(obj, cls) {
  153. if (!hasClass(obj, cls)) obj.className += " " + cls;
  154. }
  155. function removeClass(obj, cls) {
  156. if (hasClass(obj, cls)) {
  157. var reg = new RegExp('(\\s|^)' + cls + '(\\s|$)');
  158. obj.className = obj.className.replace(reg, ' ');
  159. }
  160. }
  161. //手机发送验证码结束
  162. var state;
  163. function phoneVerificationCode(){
  164. if(phonePass){
  165. $.ajax("/ajax/regmobilephone",
  166. {
  167. type: "get",
  168. async: true,
  169. success: function(data) {
  170. if(data.success) {
  171. state=data.data;
  172. }
  173. },
  174. error: function() {
  175. $.MsgBox.Alert('message', 'fail')
  176. },
  177. data: {
  178. "mobilePhone": $("#lp_phone").val()
  179. },
  180. dataType: 'json'
  181. });
  182. }
  183. };
  184. //验证手机验证码
  185. var setpass1= false;
  186. function setPhoneCode(){
  187. var pass= $("#lp_coder").val();
  188. if(pass.length==0){
  189. $(".msgphone3").text("请输入您的验证码");
  190. }else{
  191. var hunPhone=/^[0-9]{4}$/;
  192. if(hunPhone.test(pass.trim())){
  193. $(".msgphone3").text("");
  194. setpass1 = true;
  195. }else{
  196. $(".msgphone3").text("验证码4位");
  197. }
  198. }
  199. }
  200. $("#lp_coder").blur(function(){
  201. setPhoneCode();
  202. });
  203. //设置密码
  204. var password;
  205. var setpass = false;
  206. function setPassword(){
  207. password= $("#phone_password").val();
  208. if(password.length==0){
  209. $(".msgphone4").text("请输入您的密码");
  210. }else{
  211. var hunPhone=/^[0-9a-zA-Z]{6,}$/;
  212. if(hunPhone.test(password.trim())){
  213. $(".msgphone4").text("");
  214. setpass = true;
  215. }else{
  216. $(".msgphone4").text("密码6到16位");
  217. }
  218. }
  219. }
  220. $("#phone_password").blur(function(){
  221. setPassword();
  222. });
  223. //再次确定密码
  224. var setpassagain = false;
  225. function setPasswordAgain(){
  226. var passwordAgain= $("#phone_password2").val();
  227. if(passwordAgain.length==0){
  228. $(".msgphone5").text("请再次输入您的密码");
  229. }else{
  230. var hunPhone=/^[0-9a-zA-Z]{6,}$/;
  231. if(hunPhone.test(password.trim())&&passwordAgain==password){
  232. $(".msgphone5").text("");
  233. setpassagain= true;
  234. }else{
  235. $(".msgphone5").text("密码错误");
  236. }
  237. }
  238. }
  239. $("#phone_password2").blur(function(){
  240. setPasswordAgain();
  241. });
  242. //手机注册提交
  243. $("#btnn").click(function(){
  244. if(phonePass&&setpass1&&setpassagain)
  245. {
  246. $.ajax("/ajax/regmobile",{
  247. type:"POST",
  248. async: false,
  249. success:function(data){
  250. if(data.success){
  251. loginagain();//调用登录的接口
  252. // $(".completedcover").css("display","block");
  253. // $("#afterSay").click(function(){
  254. // location.href="index.html";
  255. // });
  256. // $("#todayPerfect").click(function(){
  257. // location.href="information-add.html?id="+data.data;
  258. // });
  259. location.href="information-add.html?id="+data.data;
  260. }
  261. },
  262. error:function(){$.MsgBox.Alert('message','fail')},
  263. data:{"state":state,"mobilePhone":$("#lp_phone").val(),
  264. "validateCode":$("#lp_coder").val(),"password":$("#phone_password").val(),
  265. dataType: 'json'}
  266. });
  267. }
  268. });
  269. function loginagain(){
  270. $.ajax("/ajax/login",{
  271. type:"POST",
  272. async: false,
  273. success:function(data){
  274. },
  275. error:function(){$.MsgBox.Alert('message','fail')},
  276. data:{"pw":$("#phone_password").val(),"lk":$("#lp_phone").val()},
  277. dataType: 'json'
  278. });
  279. }
  280. //邮箱注册模块
  281. //邮箱验证
  282. var emailPass = false;
  283. function valEmail()
  284. {
  285. var email = $("#lp_email").val();
  286. var gunf=/^\w+@\w+\.((cn)|(com)|(com\.cn))$/;
  287. $.ajax("/ajax/isReg?key="+email,{
  288. type:"GET",
  289. async: true,
  290. success:function($data){
  291. if($data.data==false){
  292. $(".msgema1 span").text("您的邮箱已被注册");
  293. }else{
  294. if(gunf.test(email.trim())){
  295. $(".msgema1 span").text("");
  296. emailPass = true;
  297. }else{
  298. /*alert("请输入正确是邮箱地址");*/
  299. $(".msgema1 span").text("请输入正确是邮箱地址");
  300. emailPass = false;
  301. }
  302. }
  303. },
  304. error:function(){
  305. $.MsgBox.Alert('消息','服务器请求失败')},
  306. }
  307. );
  308. }
  309. $("#lp_email").blur(function(){
  310. valEmail();
  311. });
  312. //输入密码及确认密码
  313. var oldPass = false;
  314. var isPass = false;
  315. function valOld()
  316. {
  317. var oldPassword = $("#mail_password").val();
  318. if(oldPassword.length==0)
  319. {
  320. $(".msgema2 span").text("请输入密码");
  321. oldPass = false;
  322. }else if(oldPassword.length < 6)
  323. {
  324. $(".msgema2 span").text("密码不少于6位,请输入正确的密码");
  325. }else
  326. {
  327. $(".msgema2 span").text("");
  328. oldPass = true;
  329. }
  330. }
  331. $("#mail_password").blur(function(){
  332. valOld();
  333. })
  334. function valNew()
  335. {
  336. var newPassword = $("#mail_password").val();
  337. var oldPassword = $("#mail_password1").val();
  338. if(oldPassword.length==0)
  339. {
  340. $(".msgema3 span").text("密码不能为空");
  341. }
  342. else if(oldPassword.length<6)
  343. {
  344. $(".msgema3 span").text("密码长度过短,至少六位");
  345. }else if(oldPassword != newPassword)
  346. {
  347. $(".msgema3 span").text("两次密码不一致");
  348. } else
  349. {
  350. isPass = true;
  351. $(".msgema3 span").text("");
  352. }
  353. }
  354. $("#mail_password1").blur(function(){
  355. valNew();
  356. })
  357. //邮箱注册提交
  358. function mailRegistration()
  359. {
  360. var mailVal = $("#lp_email").val();
  361. var passwordVal = $("#mail_password1").val();
  362. if(isPass&& emailPass)
  363. {
  364. $.ajax("/ajax/regmail",{
  365. type:"GET",
  366. async: false,
  367. success:function(data){
  368. //console.log(data);
  369. $.cookie('mailVal',mailVal);
  370. $.cookie('userId',data.data);
  371. location.href="bind-mail.html";
  372. },
  373. error:function(){
  374. $.MsgBox.Alert('消息','邮箱发送失败')
  375. },
  376. data:{"mail":mailVal,"password":passwordVal},
  377. dataType: 'json'}
  378. );
  379. }
  380. }
  381. $("#btnn1").click(function(){
  382. mailRegistration();
  383. });