Method _ jquery

Source: Internet
Author: User
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.

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.