Code for enabling and disabling server verification controls based on jquery

Source: Internet
Author: User

Application background

1. When the user needs to fill out the form.
2. The page uses the server verification control.
3. You can choose whether to enter more items. Use Display to control more items for Display and hiding, as shown in.

Click "add service content" to display the new form items, as shown in.

Click "unadd" to hide the new form item.

Problem: When you click Next, the new area form of Display = none is not verified. You need to disable the server verification control when you click "cancel Add. Otherwise, enable the server verification control.

Solution

Let's take a look at JQuery, which is mainly useful.

1. output the verification control to be disabled.
Copy codeThe Code is as follows: var ValidatorControls = new Array ('requiredfieldvalidatorname', 'requiredfieldvalidatorid ');

2. Verification is disabled by default.

Copy codeThe Code is as follows: for (var I = 0; I <ValidatorControls. length; I ++) {ValidatorEnable ($ ("#" + ValidatorControls [I]). get (0), false );}

3. Click "add service content" to enable verification.

Copy codeThe Code is as follows: for (var I = 0; I <ValidatorControls. length; I ++) {ValidatorEnable ($ ("#" + ValidatorControls [I]). get (0), true );}

4. You have done it.

Summary

In fact, the core function is ValidatorEnable. Sometimes you may not be able to really understand the example. You can be more impressed only when you are actually doing something.

Related Article

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.