function resetImage() { var obj = document.getElementById("code_img"); document.getElementById("code_img").src = "Handler/GetCaptchaImage.ashx?" + Math.random() * 100; console.log("resetImage"); } function clearMsg() { var obj = document.getElementById("lblMsg"); if (obj != undefined && obj != null) { obj.innerHTML = ""; } } setTimeout("clearMsg()", 10000); $(function () { $(document).keydown(function (event) { if (event.keyCode == 13) { $("#btn").click(); } }); $('.loginbox').css({ 'position': 'absolute', 'left': ($(window).width() - 692) / 2 }); $(window).resize(function () { $('.loginbox').css({ 'position': 'absolute', 'left': ($(window).width() - 692) / 2 }); }); var ct = $("#hCT").val(); if (ct != "" && parseInt(ct) >= 3) { $("#sp_code").show(); resetImage(); } }); function loginFn() { var user = $("#txtUser").val(); var pwd = $("#txtPwd").val(); if (user == "") { showMsg("请输入账号!"); $("#txtUser").focus(); return; } if (pwd == "") { showMsg("请输入密码!"); $("#txtPwd").focus(); return; } var code = $("#txtCode").val(); var ct = $("#hCT").val(); if (ct != "" && parseInt(ct) >= 3 && code == "") { showMsg("请输入验证码"); $("#txtCode").focus(); return; } $("#btn").attr("disabled", "disabled"); postAjax("Handler/login.ashx?", "erp_user_login", "user=" + user + "&pwd=" + pwd + "&code=" + code, function (data) { showMsg("登录成功"); window.location.href = 'index.aspx'; }, function (data) { $("#btn").removeAttr("disabled"); if (data.indexOf("验证码") != -1) { $("#txtCode").val(""); $("#txtCode").focus(); showMsg(data); resetImage(); } else if (data.indexOf("|") != -1) { var dArr = data.split('|'); showMsg(dArr[1]); var c = dArr[0]; $("#hCT").val(c); if (parseInt(c) >= 3) { $("#sp_code").show(); $("#txtCode").val(""); resetImage(); } } else { showMsg(data); } }); } function postAjax(urlStr, type, queryString, sFn, eFn, hps) { if (hps != false) progressShow(); $.ajax({ url: urlStr + "t=" + type, type: "POST", data: queryString, datatype: "json", success: function (result) { if (result == "") { alert("操作发生错误!"); progressHide(); return; } var data = $.parseJSON(result); if (data.type == "success") { progressHide(); sFn(data.result); } else { progressHide(); if (eFn != undefined) eFn(data.result); else alert(data.result); } }, error: function (data) { progressHide(); alert("操作发生错误!"); } }); } function progressHide() { $(".login_msg").empty(); } function progressShow() { $(".login_msg").html("登录中..."); } function showMsg(msg) { $(".login_msg").html(msg); }