0

我的问题是,在我的注册表单中,当它有错误消息并且用户尝试更改选项卡并再次返回注册时,错误消息仍然存在,当我更改选项卡时,我应该怎么做才能删除错误消息以及何时我再次点击注册链接?

<script src="http://code.jquery.com/jquery-1.8.1.js"></script>
    <script>
        $(function() {           
            var tabContainers = $('section.tabs > article');
            tabContainers.hide().filter('#login').show();

            $('.ultabs a').click(function () {
                tabContainers.hide();
                tabContainers.filter(this.hash).show();
                $('.ultabs a').removeClass('selected');
                $(this).addClass('selected');
                return false;
            });
        });
        function check_email() {
            var email=$("#textEmail").val();
            $.ajax(
            {
                type:"POST",
                url:"register.php",
                data: { 
                'email': email
                },
                success:function(msg) {
                    $("#checkEmail").html(msg);
                }
            });
            return false;
        }
        function check_password() {
            var pass=$("#textPassword").val();
            $.ajax(
            {
                type:"POST",
                url:"register.php",
                data: { 
                'pass': pass
                },
                success:function(msg) {
                    $("#checkPassword").html(msg);
                }
            });
            return false;
        }
    </script>

<nav id="siteNav">
    <h1>Navigation</h1>
    <ul class="ultabs">
        <li><a href="#login">Login</a></li>
        <li><a href="#register">Register</a></li>
    </ul>
</nav>
<section id="siteContent" class="tabs">
    <h1>Section</h1>
    <article id="login">
        <h1>Login</h1>
        <table>
            <tr>
                <td class="message" colspan="2"></td>
            </tr>
            <tr>
                <td>E-mail:</td><td><input type="email"></td>
            </tr>
            <tr>
                <td class="message" colspan="2"></td>
            </tr>
            <tr>
                <td>Password:</td><td><input type="password"></td>
            </tr>
            <tr>
                <td colspan="2"><input type="button"></td>
            </tr>
        </table>
    </article>
    <article id="register">
        <h1>Register</h1>
        <table>
            <tr>
                <td class="message" colspan="2"></td>
            </tr>   
            <tr>
                <td>Name:</td><td><input type="text"></td>
            </tr>
            <tr>
                <td id="checkEmail" class="message" colspan="2"></td>
            </tr>
            <tr>
                <td>E-mail:</td><td><input id="textEmail" type="email" onblur="return check_email()"></td>
            </tr>
            <tr>
                <td id="checkPassword" class="message" colspan="2"></td>
            </tr>
            <tr>
                <td>Password:</td><td><input id="textPassword" type="password" onblur="return check_password()"></td>
            </tr>
            <tr>
                <td class="message" colspan="2"></td>
            </tr>
            <tr>
                <td>Re-type:</td><td><input type="password"></td>
            </tr>
            <tr>
                <td colspan="2"><input type="button"></td>
            </tr>
        </table>
    </article>
</section>
4

2 回答 2

1

我建议您使用像 Bassistance 提供的验证器插件 - http://bassistance.de/jquery-plugins/jquery-plugin-validation/。它将处理错误消息,而无需您深入了解验证的细节......

于 2012-09-07T13:06:54.763 回答
0

您可以清除td选项卡的更改

$('.ultabs a').click(function () {
   $('.message').html('');
   // the rest of your code
});
于 2012-09-07T13:07:48.090 回答