Note:Ensure that the verification is performed before the form is submitted. If there are null items in the verification result, the form cannot be submitted and a verification error message is prompted, when the verification page property is not empty, the form is submitted normally. This part is a JS part and has nothing to do with the background business logic layer and control layer.
You can restrict the submission by using the form label or by adding the onclick event restriction on the submit button:
<Form action = ".." method = "post" onsubmit = "return check ();">
<Input type = "submit" value = "submit" onclick = "return check ()">
Case:
Copy codeThe Code is as follows:
<Form action = "./login. action" method = "post" onsubmit = "return check ();">
<Table>
<Tr>
<Td width = "451"> </td>
& Lt; td width = "378" & gt;
<Table>
<Tr>
<Td width = "60"> </td>
<Td>
<Font color = "#000000"> User name: </font>
</Td>
<Td align = "left"> <input name = "userInfo. userName" id = "userName" type = "text">
<Span id = "checkUserName"> </span>
</Td>
<Tr> <td> </td>
<Td align = "right" nowrap>
<Font color = "#000000"> password: </font>
</Td>
<Td align = "left">
<Input name = "userInfo. password" id = "password" type = "password">
<Span id = "checkPassword"> </span>
</Td>
</Tr>
<Tr>
<Td colspan = "4" align = "center" nowrap>
<Input type = "submit" id = "btnLog" value = "login">
<Input type = "reset" value = "reset">
</Td>
</Tr>
</Table>
</Form>
<! -- Introduce the js file jquery -->
Copy codeThe Code is as follows:
<Script type = "text/javascript" src = "js/common/jquery-1.5.1.min.js"> </script>
<Script type = "text/javascript">
Function check (){
Var userName = $ ("# userName"). val ();
Var password = $ ("# password"). val ();
Alert (userName );
Alert (password );
If (userName = ""){
$ ("# CheckUserName" ).html ("<font color = 'red'> the user name cannot be blank! </Font> ");
Return false;
}
If (password = ""){
$ ("# CheckPassword" ).html ("<font color = 'red'> the password cannot be blank! </Font> ");
Return false;
}
Return true;
}
</Script>