简体   繁体   English

jquery验证引擎中的条件验证

[英]conditional validation in jquery validation engine

I have a checkbox and a textbox. 我有一个复选框和一个文本框。 I require that if a checkbox is ticked then textbox becomes compulsary. 我要求如果选中一个复选框,则文本框变为强制性。 Vice versa if the textbox is filled the checkbox becomes compulsary. 反之亦然,如果文本框已填满,则复选框变为强制性。

So sample would be 所以样本会是

Name of Item - Checkbox - Expiry Date Name of Item2 - Checkbox2 - Expiry Date2 物品名称 - 复选框 - 到期日项目名称2 - 复选框2 - 到期日2

Data is fetched from the database in the array using a query. 使用查询从数组中的数据库中提取数据。

My code looks like 我的代码看起来像

<script type="text/javascript"> 
$(document).ready(function(){
    $("#sea").validationEngine();
   });

function industry(field, rules, i, options) {    
var atLeastOneIsChecked = $('input[name="extraqualification[]"]:checked').length > 0;
if (atLeastOneIsChecked == 1 )        {
if(document.getElementById('extraqualificationexpirydate<?php echo $extraqual['Id']?>').value=='')
{
   return "Please supply a certificate expiry";
}else{} }
    } </script>

You need conditional required validation. 您需要有条件的必要验证。 There is a condRequired method that you can use as follows: 有一个condRequired方法,您可以使用如下:

<input value="" type="text" name="test" id="test" />
<input class="validate[condRequired[test]]" type="text" id="test_2" name="test_2"/>

Also, make sure you are using version 2.6 or above. 此外,请确保您使用的是2.6或更高版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM