The previous example we are a unified reference jquery.validate.js so all required fields are prompted with this field is required.
Now you want to change to a dynamic prompt, such as the name if it is empty, the prompt name cannot be empty, if the password is blank, the prompt password cannot be empty.
This time we officer the rules in the code.
First, the file is introduced first.
<script src= "Js/jquery-1.8.0.min.js" type= "Text/javascript" ></script><script src= "js/ Jquery.validate.js "type=" Text/javascript "></script>
Next, declare the following HTML fragment
<form action= "" id= "Jvform" > Name: <input type= "text" name= "username" id= "username"/></br> password:< Input type= "password" name= "password" id= "password"/></br><input type= "Submit" value= "Submit"/></form >
compared to the previous class= "required" .
The final check rule is as follows:
$ (function () { $ ("#jvForm"). Validate ({ rules: { username: { required:true }, password: { Required:true } }, messages: { username: { required: "Name cannot be empty!" }, password: { Required: "Password cannot be empty!"}} );})
Run effect