Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.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 ui jQuery验证程序-同一控件的不同错误消息_Jquery Ui_Jquery Validate - Fatal编程技术网

Jquery ui jQuery验证程序-同一控件的不同错误消息

Jquery ui jQuery验证程序-同一控件的不同错误消息,jquery-ui,jquery-validate,Jquery Ui,Jquery Validate,在我的MVC验证中,我使用了一个日历控件,所有的验证都可以正常工作 var today = $('#TodayDateHf').val(); $('#myform').validate({ errorPlacement: $.calendars.picker.errorPlacement, rules: { DateFrom: { cpDate:true, cpCompareDate: { notAfter:

在我的MVC验证中,我使用了一个日历控件,所有的验证都可以正常工作

var today = $('#TodayDateHf').val();

$('#myform').validate({

    errorPlacement: $.calendars.picker.errorPlacement,

    rules: {

        DateFrom: {
            cpDate:true,
            cpCompareDate: { notAfter: '#DateTo', 'notAfter' : today } 
        },
        DateTo: {
            cpDate:true,
            cpCompareDate: { notBefore: '#DateFrom' } 
        }     

    },

    messages: { 
        DateFrom: 'Please enter a valid date less than or equal to To date',
        DateTo: 'Please enter a valid date greater than or equal to From date'

    }

});
一切正常,但我的问题是我不知道如何为同一个控件显示不同的消息


例如,为DateFrom定义了一个规则,该规则中有两个参数,但它只显示相同的错误消息。如何根据计算的参数显示不同的错误消息?

您可以使用类似的方法

messages:{
                DateFrom:{
                    cpDate:"Message1",
                    cpCompareDate: "Message2"
                }

            }