表单是否为空验证
<%@ 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> 用户名: <asp:TextBox ID="txtUserName" runat="server"></asp:TextBox> <span id="s1">*用户名不能为空</span><br /> 密 码: <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 /> 邮 箱: <asp:TextBox ID="txtemail" runat="server"></asp:TextBox> <br /> 性 别: <asp:RadioButton ID="rabtnman" runat="server" GroupName="a" Text="男" /> <asp:RadioButton ID="rabtnwoman" runat="server" GroupName="a" Text="女" /> <br /> 电 话: <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 /> 注 册:<asp:Button ID="btnsubmit" runat="server" OnClick="btnsubmit_Click" Text="注册" /> <br /> 重 置:<asp:Button ID="btnreset" runat="server" OnClick="btnreset_Click" Text="重置" /> </div> </form> </body> </html>