Jquery. validate: Specifies the location of the error message, and validate indicates the location of the error message.
This document describes how to locate the error message prompted by jquery. validate. We will share this with you for your reference. The details are as follows:
I haven't used the jquery. validate. js plug-in for a long time. I forgot about it. Alas, good things still need to be taken out frequently. Today we use jquery. validate to make a small things. A problem occurs, that is, the location of the error message. If you know it, it is very simple. I 've met before, but I forgot. Mark it now and forget it in the future. I'll look back at it. As the saying goes, good memory is worse than bad writing.
For example, you will know what is going on.
Rules: {name: {required: true, rangelength: []}, validateCode: {required: true, number: true, rangelength: [5, 5]}, messages: {name: {required: "Enter the command name", rangelength: jQuery. format ("length can be controlled at {0 }~ {1} ")}, validateCode: {required:" Enter the verification code ", number:" enter a number ", rangelength: jQuery. format ("length must be 5 bits") }}, success: function (label) {label. addClass ("error checked") ;}, submitHandler: function (form) {if ($ ("# RegionId "). val () = '0') {$ ("# citySelect "). attr ("class", "error" pai.html ('select a region '). show (); $ ("# RegionId "). attr ("class", "error");} else {$ ("# RegionId "). attr ("class", "valid"); $ ("# citySelect "). attr ("class", "valid" pai.html ('success '). show (); form. submit ();}}});
In the above code, I have not added a method for storing the error information. Let's take a look at the effect.
<Td> <input type = "text" maxlength = "30" value = "" id = "name" name = "name"> <label for = "name" generated =" true "> enter the command name </label> // the error message is automatically rooted behind the input box. </Td>
If we add the error message location method errorPlacement, let's see what the effect looks like.
Rules: {name: {required: true, rangelength: []}, validateCode: {required: true, number: true, rangelength: [5, 5]}, messages: {name: {required: "Enter the command name", rangelength: jQuery. format ("length can be controlled at {0 }~ {1} ")}, validateCode: {required:" Enter the verification code ", number:" enter a number ", rangelength: jQuery. format ("length must be 5 bits") }}, errorPlacement: function (error, element) {// error location setting method error. appendTo (element. parent (). next (); // The element here is the object for data input}, success: function (label) {label. addClass ("error checked") ;}, submitHandler: function (form) {if ($ ("# RegionId "). val () = '0') {$ ("# citySelect "). attr ("class", "error" pai.html ('select a region '). show (); $ ("# RegionId "). attr ("class", "error");} else {$ ("# RegionId "). attr ("class", "valid"); $ ("# citySelect "). attr ("class", "valid" pai.html ('success '). show (); form. submit ();}}});
Let's take a look at the effect.
<Tr> <th> <label for = "name" id = "lname"> <code title = "required"> * </code> command name </label> </th> <td> <input type = "text" maxlength = "30" value = "" id = "name" name = "name"> </td> <td> <label for = "name" generated = "true"> enter the command name </label> </td> // the error message appears, </tr>
It's easy enough. In simple things, you don't need to forget it for a long time.