前端_标准的登陆页面js代码模版(某网站借鉴)
<script> //切换到登录页面 function changeLogin() { $('#ereg').hide().find('form').trigger('reset'); $('#login').fadeIn(); } //切换到注册页 function changeReg() { $('#login').hide().find('form').trigger('reset'); $('#ereg').fadeIn(); } </script> <script> ;(function($){ jQuery.fn.eReg = function (options) { var options = $.extend({ 'notice': '#reg-msg', //提示框 'email': '#reg-email', //邮箱输入框 'password': '#reg-pwd', //密码输入框 'code': '#reg-code', //验证码输入框 'submit': '#reg-submit', //提交按钮 'regURL': '/account/eReg/', 'channel': '#reg-channel', 'protocol': '#reg-protocol' }, options); var noticeObj = $(options.notice); var emailObj = $(options.email); var passwordObj = $(options.password); var protocolObj = $(options.protocol); var channelObj = $(options.channel); if (options.ifCheckRePassword) {var repasswordObj = $(options.repassword)} if (options.ifCheckProtocol) {var protocolObj = $(options.protocol)} var codeObj = $(options.code); var getcodeObj = $(options.getcode); var submitObj = $(options.submit); var ERROR_MSGS = { "serverError":"服务器维护中(api),请稍后再试", "accountServerError":"服务器维护中(account),请稍后再试", "unknownError":"服务器错误", "clientBadParams":"手机号格式不正确", "mobileExists":"手机号已注册或已绑定过其它帐号", "sendMsgError":"短信服务器异常,请稍后再试", "tooManyRequests":"您今天的短信请求太多", "tooOften":"短信请求太频繁,请稍后再试", "invalidCode":"验证码不正确", "invalidMobile":"无效的手机号,请检查您的输入", "emptyPassword":"密码不能为空", "passwordTooLong":"密码太长", "noSuchUser":"操作失败,无此用户", "bindMobileBefore":"手机号已注册或绑定过其它帐号", "needPassword":"用户邮箱为空,需要密码", "anNotPassword":"用户有邮箱,不能输入密码", "sameEmailRegisteredBefore":"该邮箱已注册", "invalidPwdLength":"密码位数不正确", "badParams":"参数不正确" }; $(this).bind('submit', function(){return false;}); emailObj.blur(function () { checkEmail(); }); passwordObj.blur(function () { checkEmail() && checkPassword(); }); codeObj.blur(function () { checkEmail() && checkPassword() && checkCode(); }); submitObj.click(function(){ if(checkEmail() && checkPassword() && checkCode() && checkProtocol() ){ var email = $.trim(emailObj.val()) var password = $.trim(passwordObj.val()); var code = $.trim(codeObj.val()); var channel = $.trim(channelObj.val()); $.post(options.regURL, {"email": email, "password": password, "code": code, "channel": channel }, function (data) { if(data.status == 'ok'){ parent.location.reload(); }else{ var msg = typeof ERROR_MSGS[data.status] == undefined ? "服务器错误,请稍后再试" : ERROR_MSGS[data.status]; noticeObj.text(msg); } }, 'json' ) } }) //查看协议是否注册 function checkProtocol() { if('checked' !== protocolObj.attr('checked')) { noticeObj.text('请阅读并同意用户协议'); return false; } return true; } //检测邮箱是否正确 function checkEmail() { var email = $.trim(emailObj.val()); if(email == '') { noticeObj.text('邮箱不能为空'); return false; } if(!/^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/i.test(email)){ noticeObj.text('邮箱格式不正确'); return false; } noticeObj.html(' '); return true; } //检测密码是否正确 function checkPassword () { var password = $.trim(passwordObj.val()); if(password.length < 6 ){ noticeObj.text('密码过短,不能小于6个字符'); return false; }else if( password.length > 32){ noticeObj.text('密码过长,不能大于32个字符'); return false; } noticeObj.html(' '); return true; } //检测验证码 function checkCode () { var codeNum = $.trim(codeObj.val()); if(codeNum == '' ){ noticeObj.text('验证码不能为空'); return false; }else{ noticeObj.html(' '); return true; } } return $(this); } })(jQuery); $('#ereg form').eReg({}); </script>