表单是否为空验证

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script src="JS/jquery-3.3.1.min.js"></script>
     <script>
         $(function () {
             $("#txtUserName").blur(function () {
                 val = $(this).val();
                 if (val.length == 0) {
                     $(this).next().show();
                 }
                 else {
                     document.getElementById("s1").style.display = "none";
                 }
             });

             $("#txtpwd").blur(function () {
                 val = $(this).val();
                 if (val.length == 0) {
                     $(this).next().show();
                 }
                 else {
                     document.getElementById("s2").style.display = "none";
                 }
             });

             $("#txtconfirm").blur(function () {
                 val = $(this).val();
                 if (val.length == 0) {
                     $(this).next().show();
                 }
                 else {
                     document.getElementById("s3").style.display = "none";
                 };
                 //$("#form1").submit(function () {

                 //    $("#txtpwd").blur();
                 //    $("#txtconfirm").blur();                        
                 //})
             })
         })
    </script>
    <title></title>
    <style>
        span {
            display: inline-block;
        }

        #s1, #s2, #s3 {
            color: #f00;
            display: none;
        }
    </style>  
</head>
<body>
    <form id="form1" runat="server">
        <div>
            用户名:&nbsp;        
            <asp:TextBox ID="txtUserName" runat="server"></asp:TextBox>
             <span id="s1">*用户名不能为空</span><br />&nbsp; 码:&nbsp; 
        <asp:TextBox ID="txtpwd" runat="server" TextMode="Password"></asp:TextBox>
            <span id="s2">*密码不能为空</span><br />
            确认密码:
        <asp:TextBox ID="txtconfirm" runat="server"></asp:TextBox>
            <span id="s3">*密码不能为空</span><br />&nbsp; 箱:&nbsp; 
        <asp:TextBox ID="txtemail" runat="server"></asp:TextBox>
            <br />&nbsp; 别:       
        <asp:RadioButton ID="rabtnman" runat="server" GroupName="a" Text="" />
            <asp:RadioButton ID="rabtnwoman" runat="server" GroupName="a" Text="" />
            <br />&nbsp; 话:&nbsp; 
        <asp:TextBox ID="txtphone" runat="server"></asp:TextBox>
            <br />
            所在城市:
            <asp:DropDownList ID="DDL" runat="server">
                <asp:ListItem>洛阳</asp:ListItem>
                <asp:ListItem>许昌</asp:ListItem>
            </asp:DropDownList>
            <br />&nbsp; 册:<asp:Button ID="btnsubmit" runat="server" OnClick="btnsubmit_Click" Text="注册" />

            <br />&nbsp; 置:<asp:Button ID="btnreset" runat="server" OnClick="btnreset_Click" Text="重置" />
        </div>
    </form>
</body>
</html>

 

posted @ 2018-03-21 10:08  你的斗志并没有失去  阅读(784)  评论(0编辑  收藏  举报