<script src="jquery-1.7.2.min.js" type="text/javascript"></script> <script type="text/jscript"> function notnull() { var count = 0; $("input[type=text]").each(function () { if ($(this).val() == '') { alert('请填写完整信息!'); count++; return false; } }); if (count > 0) { return false; } } </script>
<body> <form id="form1" runat="server"> <div> <input id="Text1" type="text" /><br /> <input id="Text2" type="text" /><br /> <input id="Text3" type="text" /><br /> <input type="submit" id = "handon" value=" 提交用户 " runat ="server" onclick="return notnull()" onserverclick="Addnew" /> <asp:Button ID="Button1" runat="server" Text="Button" onclick="Addnew" /> </div> </form> </body>
后台代码 Addnew事件:
protected void Addnew(object sender, EventArgs e) { Response.Write("<script>alert('用户名和密码不能为空!')</script>"); }
填写部分信息:
填写全部信息: