Jquery. validate: Specifies the location of the error message, and validate indicates the location of the error message.

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.