日期:2014-05-16 浏览次数:20492 次
<script language="javascript" type="text/javascript"> hostURl ="<%=base%>"; //客户端检查基本的邮箱信息 function checkClientEmail(userEmail){ var emailReg = new RegExp("^[-_A-Za-z0-9]+@([_A-Za-z0-9]+\.)+[A-Za-z0-9]{2,3}$"); if(userEmail.trim()==""){ $("#emailTip").html("<font color='red'>請輸入郵箱</font>"); $("#userEmail").focus(); return false; }else{ if(emailReg.test(userEmail)){ $("#emailTip").html(""); return true; }else{ $("#emailTip").html("<font color='red'>請正确輸入郵箱</font>"); $("#userEmail").focus(); return false; } } } //服务器端检查该邮箱是否存在 function checkServerEmail(userEmail){ var isServerExisted=true; $.ajax( { url : hostURl + '/user/checkEmail.action', type : "post", data : { email : userEmail }, dataType : 'text', error : function() { $("#emailTip").html("<font color='red'>請求出錯,請稍後再試</font>"); $("#userEmail").focus(); }, success : function(data) { var ret = eval("(" + data + ")"); if (ret.msg == "success") { isServerExisted=false; $("#userEmail").attr("class","unchangeable").attr("readonly","readonly"); $("#emailTip").html("<font color='green'>該郵箱可以使用</font>"); }else { $("#emailTip").html("<font color='red'>該郵箱已經存在,請輸入其它郵箱</font>"); $("#userEmail").focus(); } } }); return isServerExisted; } //当邮箱检查通过后检查其它字段信息 function submitUserInfoByCheck(){ //普通字段 var userId=$("#userId").val().trim(); var userRealName=$("#userRealName").val().trim(); var userGender=$("input[name='user.gender']:checked").val(); var userInterest=$("#userInterest").val().trim(); var userAddress=$("#userAddress").val().trim(); var userEmail=$("#userEmail").val().trim(); var userPhone=$("#userPhone").val().trim(); //必须的字段 var userPassword=$("#userPassword").val().trim(); var userScreenName=$("#userScreenName").val().trim(); //单独提取出来的日期类型的生日 var userBirthday=$("#userBirthday").val().trim(); if(userScreenName=="") { $("#screenNameTip").html("<font color='red'>請輸入昵稱后再提交</font>"); $("#userScreenName").focus(); return false; } if(userPassword==""){ $("#userPasswordTip").html("<font color='red'>請輸入密碼后再提交</font>"); $("#userPassword").focus(); return false; }else if(userPassword.length <6) { $("#userPasswordTip").html("<font color='red'>輸入的密碼長度不能小於6位</font>"); $("#userPassword").focus(); return false; } //封装user对象属相让struts自动填充,让birthday单独处理 var userAttrs="user.id="+userId+"&user.name="+userRealName+"&user.userName="+userScreenName+"&user.gender=" +userGender+"&user.interest="+userInterest+"&user.address="+userAddress+"&user.email="+userEmail +"&user.phone="+userPhone+"&user.password="+userPassword; $.ajax( { url : hostURl + '/userCenter/updateUserselfModifyInfo!updateUserselfModifyInfo.action?'+userAttrs, type : "post", data : { userBirthday : userBirthday }, dataType : 'json', error : function() { alert("抱歉,服務器忙,請您稍後再試!"); }, success : function(data) { if (data.status) { alert("修改信息成功"); window.location.href = hostURl + "/userCenter/diplayUserInfo!getUserInfo.action"; }else { alert("抱歉,服務器忙,請您稍後再試!"); } } }); } //基本信息验证结束后就提交 function updateUserInfo(){ var isClientChecked; var isServerExisted; var emailType=$("#userEmail").attr("class"); if(emailType=="changeable"){ var userEmail=$("#userEmail").val().trim(); isClientChecked=checkClientEmail(userEmail); if(isClientChecked){ isServerExisted=checkServerEmail(userEmail); if(!isServerExisted){ submitUserInfoByCheck(); } } }else{ submitUserInfoByCheck(); } } </script>
<div> <h2>基本資料</h2> <input id="userId" type="hidden