01
2012
05

jQuery实现注册功能

    <script type="text/javascript">
        var jq = jQuery.noConflict();
        var is_or_no = 0;
        var istrue = false;
        //email的onchange实践触发的函数,先判断邮箱格式,如果合法,再验证邮箱是否已被注册is_or_no变量记录是否已被注册,后边要用
        function get_email() {
            //            var reg = /^[a-zA-Z]([a-zA-Z0-9]*[-_.]?[a-zA-Z0-9]+)+@([\w-]+\.)+[a-zA-Z]{2,}$/;
            var reg = /^[_a-zA-Z\d\-\.]+@[_a-zA-Z\d\-]+(\.[_a-zA-Z\d\-]+)+$/;
            if (!reg.test(jq("#email").val())) {
                jq("#point_email").remove();
                jq("#have_register").replaceWith('<div id="have_register" class="reg-tip" style="visibility:visible;" >邮箱格式不正确</div>');
            } else {
                jq.get(
                        '/ashx/Dd_have_or_not_register.ashx',
                        {
                            email: jq("#email").val()
                        },
                        function (data) {
                            if (data == "0") {
                                jq("#point_email").remove();
                                jq("#have_register").replaceWith('<div id="have_register" class="reg-tip" style="visibility:visible;" >邮箱已被注册</div>');
                                jq("#have_register").show();
                                is_or_no = 0;
                            }
                            if (data == "1") {
                                jq("#have_register").hide();
                                is_or_no = 1;
                            }
                        }
                        );
            }
                }
                jq(document).ready(function () {
                    jq("#point_blogname").hide();
                    jq("#point_email").hide();
                    jq("#point_password").hide();
                    jq("#point_repassword").hide();
                    jq("#have_register").hide();

                    //input获得焦点里面的标签内容颜色变浅,显示提示信息
                    jq("#blogname").focus(function () {
                        jq("#point_blogname").show();
                        jq("#point_blogname").html("给你的博客起个名字")
                        //jq("#lable_blogname").fadeTo(0, 0.4);
                        jq("#lable_blogname").hide();

                    });
                    //input失去焦点,如果内容为空,标签内容变深,显示提示信息
                    jq("#blogname").blur(function () {
                        jq("#point_blogname").hide();
                        if (jq("#blogname").val() == "") {
                            //jq("#lable_blogname").fadeTo(0, 1);
                            jq("#lable_blogname").show();
                            jq("#point_blogname").show();
                        }
                        else {
                            jq.ajax({
                                type: 'get',
                                url: '/ashx/Dd_do_register.ashx',
                                data: { blogeName: jq("#blogname").val(), type: "check_blogName", time: new Date().getDate() },
                                success: function (data) {
                                    if (data == "11") {
                                        jq("#point_blogname").show();
                                        jq("#point_blogname").html("该昵称太受欢迎了,换个吧~");
                                        istrue = false;
                                    }
                                    else {
                                        istrue = true;
                                    }
                                },
                                error: function () {
                                    istrue = false;
                                }
                            });
                        }
                    });


                    jq("#email").focus(function () {
                        jq("#point_email").show();
                        //jq("#lable_email").fadeTo(0, 0.4);
                        jq("#lable_email").hide();
                    });
                    jq("#email").blur(function () {
                        jq("#point_email").hide();
                        if (jq("#email").val() == "") {
                            //jq("#lable_email").fadeTo(0, 1);
                            jq("#lable_email").show();
                            jq("#point_email").show();
                        }
                    });


                    jq("#password").focus(function () {
                        jq("#point_password").show();
                        //jq("#lable_password").fadeTo(0, 0.4);
                        jq("#lable_password").hide();
                    });
                    jq("#password").blur(function () {
                        jq("#point_password").hide();
                        if (jq("#password").val() == "") {
                            //jq("#lable_password").fadeTo(0, 1);
                            jq("#lable_password").show();
                            jq("#point_password").show();
                            jq("#point_password").html("设置登录密码(至少6位)");
                        }
                    });


                    jq("#repassword").focus(function () {
                        jq("#point_repassword").show();
                        //jq("#lable_repassword").fadeTo(0, 0.4);
                        jq("#lable_repassword").hide();
                    });
                    jq("#repassword").blur(function () {
                        jq("#point_repassword").hide();
                        if (jq("#repassword").val() == "") {
                            //jq("#lable_repassword").fadeTo(0, 1);
                            jq("#lable_repassword").show();
                            jq("#point_repassword").show();
                        }
                    });

                    //注册按钮提交  先判断四个input里是否为空,密码是否一致,如果都合法注册
                    jq("#submit").click(function () {
                        if (check() == true) {
                            jq.ajax({
                                type: 'post',
                                url: '/ashx/Dd_do_register.ashx',
                                data: { blogname: jq('#blogname').val(), email: jq('#email').val(), password: jq('#password').val(), type: "Reg" },
                                success: function (data) {
                                    if (data == "1") {
                                        is_or_no = 0;
                                        window.location.href = "/Web/Dd_Eamil_active/Dd_Email_send.aspx";
                                    }
                                    else {
                                        alert("注册失败");
                                        window.location.href = "/Web/Dd_register.aspx";
                                    }
                                },
                                error: function () {

                                }
                            });
                        }
                    });
                });
                function check() {          
                    if (jq("#blogname").val() != "") {
                        if (jq("#email").val() != "") {
                            if (jq("#password").val() != "") {
                                if (jq("#repassword").val() != "") {
                                    if (jq("#repassword").val().length >= 6) {
                                        if (jq("#password").val() == jq("#repassword").val()) {
                                            if (is_or_no == 1) {
                                                if (istrue) {
                                                    return true;
                                                }
                                                else {
                                                    return false;
                                                }
                                            }
                                            else {
                                                return false;
                                            }
                                        }
                                        else {
                                            jq("#point_repassword").show();
                                            return false;
                                        }
                                    }
                                    else {
                                        jq("#point_password").show();
                                        jq("#point_password").html("密码长度过短,换个长的吧~");
                                    }
                                }
                                else {
                                    return false;
                                }
                            }
                            else {
                                return false;
                            }
                        }
                        else {
                            return false;
                        }
                    }
                    else {
                        return false;
                    }
                }   
    </script>

« 上一篇下一篇 »

发表评论:

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