Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery:如何在两个字段中的最后一个字段进行验证_Jquery_Forms_Validation - Fatal编程技术网

jQuery:如何在两个字段中的最后一个字段进行验证

jQuery:如何在两个字段中的最后一个字段进行验证,jquery,forms,validation,Jquery,Forms,Validation,在我的表单中,有两个字段的ID是“partita_iva”和“codice_fiscale”。我需要至少有一个不是空的。因此,在stackoverflow中,我发现了以下内容: codice_fiscale: { required: "#partita_iva:empty", remote: { url: "include/utils/checkCliente.php", type: "post",

在我的表单中,有两个字段的ID是“partita_iva”和“codice_fiscale”。我需要至少有一个不是空的。因此,在stackoverflow中,我发现了以下内容:

codice_fiscale: {
        required: "#partita_iva:empty",
        remote: {
            url: "include/utils/checkCliente.php",
            type: "post",
            data: {
                id: id_cliente,
                cf_ck: function() {
                    return jQuery("#codice_fiscale").val();
                }
            }
        }
    },

    partita_iva: {
        required: "#codice_fiscale:empty",
        remote: {
            url: "include/utils/checkCliente.php",
            type: "post",
            data: {
                id: id_cliente,
                piva_ck: function() {
                    return jQuery("#partita_iva").val();
                }
            }
        }
    },
而且消息是

codice_fiscale: {
        remote: "Codice fiscale già esistente!",
        required: "Inserisici il codice fiscale del cliente privato",
    },

    partita_iva: {
        required: "Inserisci la partita IVA del cliente",
        remote: "Partita IVA già esistente!",
    },
因此,如果两个都为空,我将正确地得到这两个的错误消息。不幸的是,如果我填写“
codice\u fiscale
”或“
partita\u iva
”,那么我仍然会收到另一个字段的错误消息……我在哪里出错

解决方案:

<script type="text/javascript" src="js/plugins/jquery.validate.min.js"></script>

codice_fiscale:{

 //required: true, 
 required: function(element) {
             return !jQuery("#partita_iva").is(':filled'); /***/
           },
...
}

partita_iva:{

 //required: true, 
 required: function(element) {
             return !jQuery("#codice_fiscale").is(':filled'); /***/
           },
...
}
因为

:empty

(正如我以前所做的)不起作用,它被禁止使用

您正在使用某种验证插件吗?这是:
:empty