编写网页时遇到了奇怪的东西

时间:2016-06-16 11:16:23

标签: php mysql ajax

其实我正在注册页面上工作。我想检查输入realname和email等的列是否有效。当输入无效时,我将直接在输入字段下显示错误消息。但是,我发现.html函数只显示消息一秒钟然后消失。我需要一些帮助。感谢

function register(){
    var name = $('#name').val();
    var username = $('#username').val();
    var mail = $('#mail').val();
    var pass = $('#pass').val();
    if (username.trim() != '')
    {
        if (name.trim() != '')
        {
            $.post("checkusername.php", {name: name},
                function(result){
                    if (result == 1)
                    {
                        if (pass.trim() != '')
                        {
                            if (filter_var($mail, FILTER_VALIDATE_EMAIL))
                            {
                                $.post("register.php"), {realname: username, nickname: name, email: mail, password: pass};
                                window.location.replace("login.php");
                            }
                            else
                            {
                                $('#email').html("<br>Invalid");
                                $('#email').css({"color":"red", "font-weight":"bold"});
                            }
                        }
                        else
                        {
                            $('#pas').html("<br>Cannot Be Empty");
                            $('#pas').css({"color":"red", "font-weight":"bold"});
                        }
                    }
                    else
                    {
                        $('#result').html("<br>Not Available");
                        $('#result').css({"color":"red", "font-weight":"bold"});
                    }
                });
        }
        else
        {
            $('#result').html("<br>Cannot Be Empty");
            $('#result').css({"color":"red", "font-weight":"bold"});
        }
    }
    else
    {
        $('#result1').html("<br>Cannot Be Empty");
        $('#result1').css({"color":"red", "font-weight":"bold"});
    }
}

0 个答案:

没有答案