废话不多说了,直接给大家贴代码了,具体代码如下所示:
<script type="text/JavaScript"> //获取url中的参数 $(function(){ var userName = window.location.href; var aa = userName.indexOf("="); console.log(userName); if (aa == -1) return ""; userName=userName.substring(aa+1); //给hidden赋值并显示 $("#userName").val(userName).attr("type","text"); //ajax请求修改密码 var rePassword = $("#repeatPassword").val(); //6到15位字母或数字 var reg=/^[0-9a-zA-Z]{6,15}$/; //新密码校验 $("#newPassword").blur(function(){ $("#msg").css("display","none"); var newPassword = $("#newPassword").val(); if(newPassword==""||newPassword==null){ $("#msg").html("请输入新密码!").css("display","block"); }elseif(!reg.test(newPassword)){ $("#msg").html("密码格式不正确,请重新输入!").css("display","block"); } }); //重复密码校验 $("#repeatPassword").blur(function(){ var newPass = $("#newPassword").val(); var repPass = $("#repeatPassword").val(); if(newPass != repPass){ $("#msg").html("两次输入密码不一致,请重输!").css("display","block"); } }); //表单提交前校验 $("#updateBtn").click(function(){ var flag = true; var newPass = $("#newPassword").val(); var repPass = $("#repeatPassword").val(); var reg1=/^[0-9a-zA-Z]{6,15}$/; if(!reg1.test(newPass)||newPass!=repPass||newPass ==""||newPass==null){ flag = false; } if(flag){ $.ajax({ url:"/HuaMuWebsite/userManage/editPassword"+userName, type:"POST", async:false, data:$("#fm").serialize(), //表单数据序列化, 可以对form表单进行序列化,从而将form表单中的所有参数传递到服务端。 success:function(data){ //json字符串转为json对象 var jsonObj=eval("("+data+")"); if(jsonObj.success != null){ alert(jsonObj.success); window.location.href="/HuaMuWebsite/admin/login.html" rel="external nofollow" ; }else{ alert(jsonObj.failure); } }, error:function(e){ alert("请求出错!"); } }); } }); }); </script>