Home  >  Article  >  Web Front-end  >  Enabling and disabling code of server validation control based on jquery_jquery

Enabling and disabling code of server validation control based on jquery_jquery

WBOY
WBOYOriginal
2016-05-16 18:28:331051browse

App background

1. When users need to fill in a form.
2. The page uses server verification control.
3. The user can choose whether to fill in more items. The display and hiding of more items are controlled by Display, as shown below.

Enabling and disabling code of server validation control based on jquery_jquery

Click "Add Service Content" to display the new form items, as shown below.

Enabling and disabling code of server validation control based on jquery_jquery

Click "Cancel Add" to hide the newly added form items.

Problem: When the user clicks Next, the new area form with Display=none is not verified. The server verification control needs to be disabled when the user clicks "Cancel Add". Otherwise, enable server authentication controls.

Solution

Let’s use JQuery to do it, mainly because it’s so easy to use.

1. Output the validation control to be disabled.

Copy code The code is as follows:
var ValidatorControls = new Array('RequiredFieldValidatorName','RequiredFieldValidatorID');


2. Verification is disabled by default.

Copy code The code is as follows:
for(var i = 0; i < ValidatorControls. length; i ){ValidatorEnable($("#" ValidatorControls[i]).get(0), false);}


3. Enable verification when clicking "Add Service Content".

Copy code The code is as follows:
for(var i = 0; i < ValidatorControls. length; i ){ValidatorEnable($("#" ValidatorControls[i]).get(0), true);}


4. Already done.

Summary

In fact, the core function is ValidatorEnable(). Sometimes you may not really understand by looking at examples. Only by actually doing it can you have a deeper impression.
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn