|
- var user_login = {
- /**
- * 初始化的函数,定义一些当页面加载就出发的东西
- */
- initEvent: function(){
- $("#subnitButt1").mouseover(function(){
- this.src = "image/login_submitBtn2.gif";
- }).mouseout(function(){
- this.src = "image/login_submitBt1.gif";
- }).click(function(){
- user_login.submitForm();
- });
- //定义验证码图片框
- var oVCode = $("input[name=vcode]");
- var pos = getAbsPostion(oVCode);
- var left = pos.left;
- var top = pos.top + oVCode[0].offsetHeight + 2;
- $("div.validateCodeDiv").click(function(){
- user_login.changeCode();//改变图片
- event.stopPropagation();
- });
- },
- /**
- * form
- * 表单提交的函数
- */
- submitForm: function(){
- var oAcc = $("input[name=account]");
- if (oAcc.val().trim().length == 0) {
- $("#messBox").html("请输入用户名");
- oAcc.focus();
- return;
- }
- var oPass = $("input[name=passwd]");
- if (oPass.val().trim() == 0) {
- $("#messBox").html("清输入密码");
- oPass.focus();
- return;
- }
- var oVcode = $("input[name=vcode]");
- if (oVcode.val().trim().length == 0) {
- $("#messBox").html("请输入验证码");
- oVcode.focus();
- return;
- }
- var url = "userLogin.do";
- var para = getFormPara("from[name=frml]");
- $.post(url, para, function(data){
- if (data == "vcode error") {//这个data的数值是后台返回的
- $("#messBox").html("验证码错误");
- }
- else
- if (data == "userpass error") {
- $("#messBox").html("用户名或密码错误");
- }
- else {
- location = "home.do";
- }
- user_login.changeCode();
- });
- },
- //改变验证码图片的颜色
- showHideVcodeImg: function(){
- $("input[name=account],input[name=passwd],#submitBtn").click(function(){
- $("div.validateCodeDiv").css("display","none");
- }).focus(function(){
- $("div.validateCodeDiv").css("display", "block");
- });
- $(document).click(function(){
- $("div.validateCodeDiv").css("display", "none");
- });
- },
- //改变验证码的函数
- changeCode:function(){
- $("imgVcode").attr("src","servlet/getVcode?ts="+new Date().getTime());
- }
- };
- /**
- * 当页面加载哦时候就调用initEvent()函数
- */
- $().ready(function(){
- user_login.initEvent();
- });
复制代码 |
|