22
2012
04

jQuery、ashx 登录功能的实现

<script type="text/javascript" language="javascript">

    var jq = jQuery.noConflict();

    jq(document).ready(function () {
    jq("#text_mail").focus(function () {  //邮件框的颜色变化,点击离开的变化
        jq("#mail_error").hide();
        jq("#text_mail").css("border", "1px solid #00B7EF");
    });
    jq("#text_mail").blur(function () {
        jq("#text_mail").css("border", "1px solid #DBDFE6");
        check_email();
    });
    jq("#text_psw").focus(function () { //密码框的颜色变化,点击离开的变化
        jq("#psw_error").hide();
        jq("#text_psw").css("border", "1px solid #00B7EF");
    });
    jq("#text_psw").blur(function () {
        jq("#text_psw").css("border", "1px solid #DBDFE6");
        check_psw();
    });

    jq("#submit").click(function () {  //执行登录
        if (check_email() == true && check_psw() == true) {  //邮件密码的判断
            jq.post(
                        '/ashx/Dd_do_login.ashx',
                        {
                            email: jq("#text_mail").val(),
                            password: jq("#text_psw").val()
                        },
                        function (data) {
                            var arryuser = data.split(',');
                            if (arryuser[0] == '11') {
                                jq.ajax({
                                    type: "post",
                                    url: '/ashx/Dd_userExit.ashx',
                                    data: { type: "login", user_ID: arryuser[1], user_Name: arryuser[2], user_Email: jq("#text_mail").val(), user_check: jq("#check_state").attr("checked") },
                                    success: function (data) {
                                        window.location.href = "/Default.aspx";
                                    }
                                });
                            }
                            else if (arryuser[0] == "01") {
                                alert("不好意思,你的账号还没有激活,请登录邮箱进行账号激活!");
                            }
                            else {
                                jq("#error_div").show();
                                jq("#error_mess").text("邮箱或密码不正确!");
                                return false;
                            }
                        }

                    );
        }
        else {
            return false;
        }

    });
});


function check_email() {
    if (jq("#text_mail").val() == "") {
        jq("#mail_error").show();
        return false;
    }
    else {
        var reg = /^[_a-zA-Z\d\-\.]+@[_a-zA-Z\d\-]+(\.[_a-zA-Z\d\-]+)+$/
        if (!reg.test(jq("#text_mail").val())) {
            jq("#error_div").show();
            jq("#error_mess").text("邮箱格式不正确!");
            return false;
        }
        else {
            jq("#error_div").hide();
            return true;
        }
    }
}
function check_psw() {
    if (jq("#text_psw").val() == "") {
        jq("#psw_error").show();
        return false;
    }
    else {
        return true;
    }

</script>

 

      <div id="user_mes">
                    <div id="user_email">                                              
                        <input id="text_mail" type="text" name="mail" /> 
                        <label id="mail_error" for="text_mail" >邮箱账号</label>
                    </div>                           
        <div id="user_psw">                     
                       <input id="text_psw" type="password" />                     
                       <label id="psw_error" for="text_psw">密码</label>
                    </div> 
                    <div id="btn_login">                         
            <a id="login">
             <button id="submit" class="login1 " type="submit"></button>
            </a>
                    </div>
    </div>

« 上一篇下一篇 »

评论列表:

谢谢博主分享学习了啊

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。