This article mainly introduces jquery. the location of the error message prompted by validate is analyzed by jquery. validate provides related tips for prompting the location of error messages. For more information about jquery, see the following example. the location of the error message prompted by 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.
Enter the command name// The error message is automatically rooted behind the input box.
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.
*
Command nameEnter the command name// The error message comes here,
It's easy enough. in simple things, you don't need to forget it for a long time.