<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script> <script type="text/javascript"> function yz() { var name = $("#name").val(); if (name == "") { alert("不允许为空"); return false; } else { return true; } } </script> </head> <body> <form id="form1" runat="server"> <div> <asp:TextBox ID="name" runat="server"></asp:TextBox> <asp:Button OnClientClick="return yz();" ID="Button1" runat="server" Text="验 证" onclick="Button1_Click" /> </div> </form> </body> </html>
单击按钮首先触发OnClientClick的客户端事件,然后触发服务端的onclick事件