$(document).ready(function () { $("#txt_account").keydown(function (e) { if (e.which == 13) { $("#txt_password").focus(); } }); $("#txt_code").keydown(function (e) { if (e.which == 13) { User.Login(); } }); $("#txt_password").keydown(function (e) { if (e.which == 13) { User.Login(); } }); $("#login_button").click(function () { User.Login(); }); $("#imgcode").click(function () { User.imgcode(); }); User.init(); User.imgcode(); }); var User = { formMessage: function (msg) { $('.login_tips').find('.tips_msg').remove(); $('.login_tips').append('
' + msg + '
'); }, Login: function () { var username = $("#txt_account"); var password = $("#txt_password"); var code = $("#txt_code"); if (username.val() == "") { username.focus(); User.formMessage('请输入用户名/手机号/邮箱。'); return false; } else if (password.val() == "") { password.focus(); User.formMessage('请输入登录密码。'); return false; } // liudl 注释 暂停验证码功能 //else if (code.val() == "") { // code.focus(); // User.formMessage('请输入验证码。'); // return false; //} else { $("#login_button").attr('disabled', 'disabled').find('span').html("loading..."); $.ajax({ url: "/Login/CheckLogin", data: { username: $.trim(username.val()), password: $.trim(password.val()), code: $.trim(code.val()) }, type: "post", dataType: "json", success: function (data) { if (data.state == "success") { $("#login_button").find('span').html("登录成功,正在跳转..."); window.setTimeout(function () { var url = $("#hdUrl").val(); if (url == undefined || url == "") window.location.href = "/Home/Index"; else window.location.href = url; }, 500); } else { $("#login_button").removeAttr('disabled').find('span').html("登录"); User.imgcode(); code.val(''); User.formMessage(data.message); } } }); } }, init: function () { $('.wrapper').height($(window).height()); $(".container").css("margin-top", ($(window).height() - $(".container").height()) / 2 - 50); $(".logo").css("padding-left", ($(".logo").width() - ($("#logoId").width() + $("#logoName").width())) / 2 + 10); $(window).resize(function (e) { $('.wrapper').height($(window).height()); $(".container").css("margin-top", ($(window).height() - $(".container").height()) / 2 - 50); $(".logo").css("padding-left", ($(".logo").width() - ($("#logoId").width() + $("#logoName").width())) / 2 + 10); }); $("#txt_account").focus(); }, imgcode: function () { $("#imgcode").attr("src", "/Login/GetAuthCode?time=" + Math.random()); } }