function getBasePath(){ var els = document.getElementsByTagName('script'), src; for (var i = 0, len = els.length; i < len; i++) { src = els[i].src || ''; if (/UI\/js\/register.js/.test(src)) { return src.split('UI\/js\/register.js')[0]; } } return ''; } function showNotice(msg){ var regNotice = $(".regNotice"); //regNotice.removeClass("regNoticeWait"); regNotice.html(msg); if(msg.length>0){ regNotice.show(); }else{ regNotice.hide(); } } $(document).ready(function(){ if(top.location.host!=location.host){ top.location.href = location.href; } if(top.location.href!=location.href){ var userAgent = navigator.userAgent.toLowerCase(); if(userAgent.indexOf('mobile')!=-1){ $('.page,.tips_show,.register_bd,.infobox_bd .form,.reg_inputbox,.infobox_bd .input_box,.infobox_bd .reg_msg,.infobox_bd .frm_tips,.radio_box,.infobox_bd .reg_with_form').css('width','auto'); $('.page').css('padding','0'); $('.container').css('margin','20px 0'); $('.header').hide(); $('.reg_line').css('float','none'); $('.infobox_bd .form').css('margin','0 10px'); $('.reg_field .verifyimg_p').css({ 'position': 'absolute', 'margin': '0', 'right': '10px', 'z-index': '2' }); $('.btn,.getcode').css('padding', '0 5px'); }else{ $('.page').css('width','900px').css('padding','0'); $('.container').css('margin','20px 0'); $('.tips_show').css('width','auto'); $('.header').hide(); } } //验证表单数据 var isSendCodeDis=new Array(); //var parentWidth=$("#detail_span").outerWidth(true); //国内国外选择 $("input[name='isOverseas'][type='radio']").change(function(){ var _this=$(this); var radioVal=_this.val(); if(radioVal==0){ $("#js_mobile").parents(".reg_line").find(".reg_label").addClass("must"); }else{ $("#js_mobile").parents(".reg_line").find(".reg_label").removeClass("must"); $("span[for='js_mobile']").parent().hide(); } }); $("select[name^=live]").change(function(){ var _this=$(this); var liveCountry=$("#liveCountry option:checked").text(); if(liveCountry=="选择国家"){ liveCountry=""; } var liveProvince=$("#liveProvince option:checked").text(); if(liveProvince=="选择省份"){ liveProvince=""; } var liveCity=$("#liveCity option:checked").text(); if(liveCity=="选择城市"){ liveCity=""; } //$("#addressShow").text(liveCountry+liveProvince+liveCity); //var showWidth=$("#addressShow").outerWidth(true); //$("#detail_span").find("input").css("width",(parentWidth-27-showWidth)); //$("#detail_span").css("width",$("#detail_span").find("input").width()+6); }); $(".input_box input").blur(function(){ var _this=$(this); if($.trim(_this.val())==""){ if(_this.attr("id")=="js_mobile"){ var isOverseas=$("input[name='isOverseas'][type='radio']:checked").val(); if(isOverseas!="0"){ $("#isNumExist").val(""); $("span[for='js_mobile']").parent().hide(); return; } $("span[for='js_mobile']").text('请输入正确的手机号码'); } if(_this.attr("id")=="js_email"){ $("span[for='js_email']").text('请输入正确的邮箱地址'); } _this.parent().next().show(); var index = $.inArray(_this.attr("id"),isSendCodeDis); if(index != -1){ isSendCodeDis.splice(index,1); } }else{ _this.parent().next().hide(); var index = $.inArray(_this.attr("id"),isSendCodeDis); if(index == -1){ isSendCodeDis.push(_this.attr("id")); } if(_this.attr("id")=="js_mobile"){ checkMobile(_this); } if(_this.attr("id")=="js_email"){ checkEmail(_this); } } var isOverseas=$("input[name='isOverseas'][type='radio']:checked").val(); if(isOverseas!="0"){ if($.inArray("js_email",isSendCodeDis)!=-1&&$.inArray("js_imgCode",isSendCodeDis)!=-1){ $("#getcode").attr("disabled",false).parent().removeClass("btn_disabled"); }else{ $("#getcode").attr("disabled",true).parent().addClass("btn_disabled"); } }else{ if($.inArray("js_mobile",isSendCodeDis)!=-1&&$.inArray("js_imgCode",isSendCodeDis)!=-1){ $("#getcode").attr("disabled",false).parent().removeClass("btn_disabled"); }else{ $("#getcode").attr("disabled",true).parent().addClass("btn_disabled"); } } }); //文本框绑定改变事件 $("#js_mobile,#js_email,#js_imgCode").bind("input propertychange",function(){ var _this=$(this); if(_this.val()!=""){ var index = $.inArray(_this.attr("id"),isSendCodeDis); if(index == -1){ isSendCodeDis.push(_this.attr("id")); } }else{ var index = $.inArray(_this.attr("id"),isSendCodeDis); if(index != -1){ isSendCodeDis.splice(index,1); } } var isOverseas=$("input[name='isOverseas'][type='radio']:checked").val(); if(isOverseas!="0"){ if($.inArray("js_email",isSendCodeDis)!=-1&&$.inArray("js_imgCode",isSendCodeDis)!=-1){ $("#getcode").attr("disabled",false).parent().removeClass("btn_disabled"); }else{ $("#getcode").attr("disabled",true).parent().addClass("btn_disabled"); } }else{ if($.inArray("js_mobile",isSendCodeDis)!=-1&&$.inArray("js_imgCode",isSendCodeDis)!=-1){ $("#getcode").attr("disabled",false).parent().removeClass("btn_disabled"); }else{ $("#getcode").attr("disabled",true).parent().addClass("btn_disabled"); } } }) //提交数据 $("#subBtn").click(function(){ var notEmpty=checkData(); var isNumExist=$("#isNumExist").val(); if(isNumExist!='2'){ notEmpty=checkMobile($("#js_mobile")); notEmpty=checkEmail($("#js_email")); } if(notEmpty){ $("#subBtn").attr("disabled",true).parent().addClass("btn_disabled").parent().addClass("sub_wait"); //$("#regForm").submit(); //ajax 提交 $.ajax({ type:"POST", url:"regVerify", data:$("#regForm").serialize(), dataType:'json', success:function(res){ if(res.code==-1){ var li=$("
"); li.text(res.msg); $(".regNotice").append(li); li.fadeOut(4000,function(){li.remove()}); }else if(res.code==-2){ toptips("请重新填写您的注册信息","warning"); setTimeout(function(){ location.href="https://alumni.sufe.edu.cn/regCenter"; },1000); }else if(res.code==0){ toast("操作成功") location.href="https://alumni.sufe.edu.cn/alumniHome"; }else if(res.code==1){ toast("操作成功,跳转到下一步") location.href="https://alumni.sufe.edu.cn/step_2"; } }, complete:function(){ $("#subBtn").attr("disabled",false).parent().removeClass("btn_disabled").parent().removeClass("sub_wait"); } }); } return false; }); $("#js_agree").change(function(){ var _this=$(this); var checked=_this.attr("checked"); if(checked){ $(".icon_checkbox").addClass("checked"); $("#subBtn").attr("disabled",false).parent().removeClass("btn_disabled"); }else{ $(".icon_checkbox").removeClass("checked"); $("#subBtn").attr("disabled",true).parent().addClass("btn_disabled"); } }); }); function checkEmail(obj){ var beret=false; var isNumExist=$("#isNumExist").val(); if(obj&&isNumExist!='2'){ var temp=$(obj); var msgText="请输入邮箱"; if($.trim(temp.val())!=""){ temp.next("#msg").remove(); var match=/[\w!#$%&'*+/=?^_`{|}~-]+(?:\.[\w!#$%&'*+/=?^_`{|}~-]+)*@(?:[\w](?:[\w-]*[\w])?\.)+[\w](?:[\w-]*[\w])?/; if(!match.test(temp.val())){ msgText="邮箱格式不正确"; $("span[for='js_email']").text(msgText).parent().show(); return false; }else{ //检测邮箱是否存在 $.ajax({ type:'POST', data:'email='+temp.val(), url:'reg_check_email', async:false, dataType: 'json', success: function(result){ if(result){ $("span[for='js_email']").text("请输入正确的邮箱").parent().hide(); if(result.code==0){ beret = true; }else if(result.code==1){ msgText="邮箱已经被注册,是否忘记密码?"; $("span[for='js_email']").html(msgText).parent().show(); return false; } } } }); } } } return beret; } function checkMobile(obj){ var beret=false; if(obj){ $("#isNumExist").val(""); var temp=$(obj); var msgText="请输入手机"; if($.trim(temp.val())!=""){ temp.next("#msg").remove(); var match=/\w+[@]\w+[.]\w+/; if(isNaN(temp.val())){ msgText="手机格式不正确"; $("span[for='js_mobile']").text(msgText).parent().show(); return false; }else{ //检测手机是否存在 $.ajax({ type:'POST', data:'handsetFirst='+temp.val(), url:'reg_check_hand', async:false, dataType: 'json', success: function(res){ if(res){ $("span[for='js_mobile']").text("请输入正确的手机号码").parent().hide(); if(res.code==0){ beret = true; }else if(res.code==1){ //$("#isNumExist").val("1"); //msgText="手机已经被注册,是否忘记密码?"; //$("span[for='js_mobile']").html(msgText).parent().show(); //return false; $("#isNumExist").val("1"); msgText="手机已经被注册,是否忘记密码?"; $("span[for='js_mobile']").html(msgText).parent().show(); setTimeout(function(){ confirm({ message:'该手机号已注册,是否去登录?', okVal:'去登录', canVal:'取消', ok:function(){ location.href="https://alumni.sufe.edu.cn/alumniLogin"; } }); }); return false; } } } }); } } } return beret; } function validateErr(obj){ if(!!obj){ if($.trim($(obj).val())==""){ $(obj).focus(); $(obj).addClass("errbodd"); var timeout=200; setTimeout(function(){$(obj).parent().removeClass("errbodd")},timeout); setTimeout(function(){$(obj).parent().addClass("errbodd")},timeout*2); setTimeout(function(){$(obj).parent().removeClass("errbodd")},timeout*3); setTimeout(function(){$(obj).parent().addClass("errbodd")},timeout*4); }else{ //判断邮箱的格式 if(obj.attr("id")=='js_email'){ if($.trim($(obj).val())){ var match=/\w+[@]\w+[.]\w+/; if(!match.test($(obj).val())){ $(obj).focus(); $(obj).addClass("errbodd"); var timeout=200; setTimeout(function(){$(obj).parent().removeClass("errbodd")},timeout); setTimeout(function(){$(obj).parent().addClass("errbodd")},timeout*2); setTimeout(function(){$(obj).parent().removeClass("errbodd")},timeout*3); setTimeout(function(){$(obj).parent().addClass("errbodd")},timeout*4); return false; } } } $(obj).parent().removeClass("errbodd"); return true; } } return false; } function checkData(){ var notEmpty = false; //姓名 notEmpty=validateErr($("#js_name")); if(notEmpty){ //notEmpty=validateErr($("#js_livedetail")); } var isOverseas=$("input[name='isOverseas'][type='radio']:checked").val(); if(isOverseas=="0"){ if(notEmpty){ //手机号 notEmpty=validateErr($("#js_mobile")); } } if(notEmpty){ //邮箱 notEmpty=validateErr($("#js_email")); } //var hand=$.trim($("#handsetFirst").val()); //var mail=$.trim($("#mailFirst").val()); return notEmpty; }