asp.net客户端OnClientClick方法
OnClientClick方法真乃神器,客户端方法,和服务器端的onclick时间不冲突。
<asp:Button ID="btnLogin" runat="server" Text="登录" Height="26px" onclick="btnLogin_Click" OnClientClick="return Check()" Width="68px" />
function Check() { var name = document.getElementById("txt_user_num").value; var pwd = document.getElementById("txt_user_pwd").value; var code = document.getElementById("tbcode").value; if (name == "" || pwd == "" || code == "") { document.getElementById("txt_user_num").style.backgroundColor = "Red" return false; }else{ return true }