獲取值之后的判斷
$(function () { $("#btlogin").click(function () { var txtaccount = $("#txtaccount").val();//獲取賬號 var txtpassword = $("#txtpassword").val();//獲取密碼 if (txtaccount == "") { $("#txtaccount").focus(); formMessage('登錄賬戶不能為空', 'warning'); return false; } else if (txtpassword == "") { $("#txtpassword").focus();//使鼠標聚焦到密碼框里面 formMessage('登錄密碼不能為空', 'warning'); return false; } else { formMessage('正在登錄...', 'succeed'); window.setTimeout(function () { var postData = { Account: escape(txtaccount),//escape()對字符串編碼 Password: escape($.md5(txtpassword)) } getAjax('/Login/CheckLogin', postData, function (rs) { if (parseInt(rs) == -1) { $("#txtaccount").focus(); formMessage('登錄賬戶不存在', 'error'); } else if (parseInt(rs) == 2) { $("#txtaccount").focus(); formMessage('登錄賬戶被系統鎖定', 'error'); } else if (parseInt(rs) == 4) { $("#txtaccount").focus(); $("#txtpassword").val(""); formMessage('登錄密碼錯誤', 'error'); } else if (parseInt(rs) == 3) { formMessage('登錄驗證成功,正在跳轉首頁', 'succeed'); setInterval(Load, 1000); } else { alert(rs); } }); }, 500); } }) }
登錄成功后加載的界面:
//登錄加載 function Load() { var Index = $.cookie('UItheme'); if (Index) { window.location.href = '@Url.Content("~/Home/")' + Index; } else window.location.href = '@Url.Content("”)'; } return false; }
formMessage:
//提示信息 function formMessage(msg, type) { $('.form-message').html('');//先清空數據 $('.form-message').append('<div class="form-' + type + '-text">' + msg + '</div>'); }