RSS订阅悠然探索,悠然索取
你的位置:首页 » 技术文章 » 正文

Jquery自动验证

选择字号: 超大 标准 发布时间:2010-1-4 17:15:7 | 作者:admin | 0个评论 | 人浏览

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="frmAuto.aspx.cs" Inherits="StudyJQuery.jsAuto.frmAuto" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>

    <script src="../js/jquery-1.3.2-vsdoc2.js" type="text/javascript"></script>

    <style type="text/css">
        .diverror
        {
            border: 1px dashed #FF0000;
            background-color: #CCCCCC;
            margin: 0px;
            padding: 0px;
            font-size: 12px;
            line-height: 25px;
        }
        .divright
        {
            font-size: 12px;
            line-height: 25px;
            background-color: #FFFFFF;
            margin: 0px;
            padding: 0px;
            border-top-style: none;
            border-right-style: none;
            border-bottom-style: none;
            border-left-style: none;
        }
    </style>

    <script language="javascript" type="text/javascript">
        $(document).ready(function() {
            //        $("form input[class],select[class]").each(function(index, e) {
            //            alert(index + e.id);

            //            });

            $("form input[class],select[class]").blur(function() {
                //alert($(this).val());
                var id = $(this).attr("id");

                var $ErrorMessage; //= $("<div id = err'" + id + "'></div>");
                $ErrorMessage = $(this).parent().find("#err" + id);
                //alert(typeof ($ErrorMessage[0]));
                // if (typeof ($("#jd_shadow")[0]) == "undefined") {
                if (typeof ($ErrorMessage[0]) == "undefined") {

                    $ErrorMessage = $("<div id = err" + id + " ></div>");
                    $ErrorMessage.insertAfter($(this));
                }
                if ($(this).val() == "" || $(this).val() == null) {
                    $ErrorMessage.removeAttr("class").attr("class", "diverror");
                }
                else {
                    $ErrorMessage.removeAttr("class").attr("class", "divright");
                }
                $ErrorMessage.removeAttr("class").attr("class", "divright").attr("class", "diverror");
                $ErrorMessage.text(id + "出错!");
               
                //$(this).parent().remove("#err" + id);

            });


        });
   
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <div class="diverror">
        <table>
            <tr>
                <td>
                    用户名
                </td>
                <td>
                    <asp:TextBox ID="txtUserID" runat="server" CssClass="1"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    密码
                </td>
                <td>
                    <asp:TextBox ID="txtUserPwd" runat="server" CssClass="2"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    手机号码
                </td>
                <td>
                    <asp:TextBox ID="txtUserTel" runat="server" CssClass="3"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    EMAIL
                </td>
                <td>
                    <asp:TextBox ID="txtUserEMail" runat="server" CssClass="4"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    性别
                </td>
                <td>
                    <asp:DropDownList ID="drpUserSex" runat="server" CssClass="5">
                        <asp:ListItem Value="0">请选择</asp:ListItem>
                        <asp:ListItem Value="1">男</asp:ListItem>
                        <asp:ListItem Value="2">女</asp:ListItem>
                    </asp:DropDownList>
                </td>
            </tr>
            <tr>
                <td>
                    &nbsp;
                </td>
                <td>
                    <asp:Button ID="btnSubmit" runat="server" Text="提交" />
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>
 

标签:

猜你喜欢

发表评论

必填

选填

选填

必填,不填不让过哦,嘻嘻。

记住我,下次回复时不用重新输入个人信息

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