關於jquery登錄的一些簡單驗證。


獲取值之后的判斷  

  $(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>');
    }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM