Usage comparison of onclientclick and onclick
<Head runat = "server">
<Title> No title page </title>
<Script language = "JavaScript">
Function check ()
{
VaR email = Document. getelementbyid ('textbox1 ');
VaR Pwd = Document. getelementbyid ('textbox2 ');
If (email. value = "" | PWD. value = "")
{
Alert ("complete content ");
Return false;
}
Else
{
VaR mailstr =/("W) +) @ (" W) +). [CC | com | net | org | TV | cn]/ig;
If (! Mailstr.exe C (email. Value ))
{
Alert ('email address is incorrectly written! "N please enter it again! ');
Email. value = '';
Email. Focus ();
Return false;
}
}
}
</SCRIPT>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<Div>
<Asp: textbox id = "textbox1" runat = "server"> </ASP: textbox> & nbsp;
<Asp: textbox id = "textbox2" runat = "server"> </ASP: textbox>
<Asp: button id = "button1" runat = "server" text = "button" Onclientclick = "Return check ();" Onclick = "button#click1" />
</Div>
</Form>
</Body>
Execute the JavaScript function of the client first, send the page back, and then execute the server method.
Onclientclick is a client event and onclick is a server event. In addition, client events are executed first, and server events are executed later.