自己写了一个js,但是最终不能控制住最后后的提交,前面的还是比较完美,大家看到后,能帮我解决一下吗?

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link href="Css/Main.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">
        function Check( control ) {
            var userReg = /^[a-zA-Z0-9_]{1,}$/;
            var emailReg = /^.+@.+$/;
            var hiddValue = document.getElementById( "hiddValue" );
            switch ( control.id ) {
                case "txt_user_LoginName":
                    {
                        var span_user_LoginName = document.getElementById( "span_user_LoginName" );
                        span_user_LoginName.innerHTML = "";
                        if ( control.value.length > 0 ) {
                            if ( !control.value.match( userReg ) )
                                span_user_LoginName.innerHTML = "用户名格式不正确!";
                            else
                                hiddValue.value = 1;
                        }
                        else
                            span_user_LoginName.innerHTML = "此项不能为空!";
                        break;
                    }

                case "txt_user_Password":
                    {
                        var span_user_LoginName = document.getElementById( "span_user_Password" );
                        span_user_Password.innerHTML = "";
                        if ( control.value.length > 0 ) {
                            if ( !control.value.match( userReg ) )
                                span_user_Password.innerHTML = "密码格式不正确!";
                            else
                                hiddValue.value = 1;

                        }
                        else
                            span_user_LoginName.innerHTML = "密码不能为空!";
                        break;
                    }

                case "txt_user_PasswordRel":
                    {
                        var txt_user_Password = document.getElementById( "txt_user_Password" ).value;
                        var span_user_PasswordRel = document.getElementById( "span_user_PasswordRel" );
                        span_user_PasswordRel.innerHTML = "";
                        if ( control.value.length > 0 ) {
                            if ( control.value != txt_user_Password )
                                span_user_PasswordRel.innerHTML = "两次输入密码不一样!";
                            else
                                hiddValue.value = 1;
                        }
                        else
                            span_user_PasswordRel.innerHTML = "密码不能为空!";
                        break;
                    }
                case "txt_user_Email":
                    {
                        var span_user_Email = document.getElementById( "span_user_Email" );
                        span_user_Email.innerHTML = "";
                        if ( control.value.length > 0 ) {
                            if ( !control.value.match( emailReg ) )
                                span_user_Email.innerHTML = "电子邮箱格式不正确!";
                            else
                                hiddValue.value = 1;
                        }
                        else
                            span_user_Email.innerHTML = "电子邮件不能为空!";
                        break;
                    }

                default:

            }

        }
        function Empty( control ) {
            switch ( control.id ) {
                case "txt_user_LoginName":
                    {
                        var span_user_LoginName = document.getElementById( "span_user_LoginName" );
                        span_user_LoginName.innerHTML = "用户名只能由数字,字母及下划线组成。";
                        break;
                    }

                case "txt_user_Password":
                    {
                        var span_user_Password = document.getElementById( "span_user_Password" );
                        span_user_Password.innerHTML = "密码只能由数字,字母及下划线组成";
                        break;
                    }

                case "txt_user_PasswordRel":
                    {
                        var span_user_PasswordRel = document.getElementById( "span_user_PasswordRel" );
                        span_user_PasswordRel.innerHTML = "请再次输入密码!";
                        break;
                    }

                case "txt_user_Email":
                    {
                        var span_user_Email = document.getElementById( "span_user_Email" );
                        span_user_Email.innerHTML = "请输入正确格式的电子邮箱";
                        break;
                    }

                default: return false;
            }
        }
        function checkAll() {
            if ( checkEmpty() ) {
                if ( document.getElementById( "hiddValue" ).value == 1 ) {
                    return true;
                }
                return false;
            }
            return false;
        }
        function checkEmpty() {
            var inputText = document.getElementsByTagName( "input" );
            for ( var i = 0; i < inputText.length; i++ ) {
                if ( inputText[i].type == "text" )
                    if ( inputText[i].value.length < 0 || inputText[i].value.length == 0 )
                        return false;
                    else
                        return true;
            }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <table class="table ">
        <tr>
            <td class="labelCol ">
                用户名:
            </td>
            <td>
                <input id="txt_user_LoginName" type="text" class="textInput" onblur="Check(this)"
                    onfocus="Empty(this);" /><span id="span_user_LoginName" class="red">*</span>
            </td>
        </tr>
        <tr>
            <td class="labelCol ">
                密码:
            </td>
            <td>
                <input id="txt_user_Password" type="text" class="textInput" onblur="Check(this)"
                    onfocus="Empty(this);" /><span id="span_user_Password" class="red">*</span>
            </td>
        </tr>
        <tr>
            <td class="labelCol ">
                重复密码:
            </td>
            <td>
                <input id="txt_user_PasswordRel" type="text" class="textInput" onblur="Check(this)"
                    onfocus="Empty(this);" /><span id="span_user_PasswordRel" class="red">*</span>
            </td>
        </tr>
        <tr>
            <td class="labelCol ">
                邮箱:
            </td>
            <td>
                <input id="txt_user_Email" type="text" class="textInput" onblur="Check(this)" onfocus="Empty(this);" /><span
                    id="span_user_Email" class="red">*</span>
            </td>
        </tr>
        <tr style="text-align: center;">
            <td colspan="2" style="text-align: center;">
                <input id="hiddValue" type="hidden" value="0" />
                <asp:Button ID="btn_Regist" runat="server" Text="注册" OnClick="btn_Regist_Click" OnClientClick="return checkAll();" />
            </td>
        </tr>
    </table>
    </form>
</body>
</html>

posted @ 2011-04-08 00:26  易独  阅读(163)  评论(0编辑  收藏  举报
乐巴儿 一个有声音的公众号
长按,识别二维码,加关注