如何将对象节点用作变量,如下面的newEndEventDate
?
var val = $("form").validate({
rules: {
newEventDate: { required: true, regex: /^(19|20)\d\d-?(0[1-9]|1[012])-?(0[1-9]|[12][0-9]|3[01])$/ },
newEndEventDate: { required: true, regex: /^(19|20)\d\d-?(0[1-9]|1[012])-?(0[1-9]|[12][0-9]|3[01])$/, greaterThan: newEventDate },
newEventText: { required: true, maxlength: 200 },
},
messages: {
...
}
}).form();
在newEventDate
内使用newEndEventDate
会出现错误'newEventDate' is undefined
。但是如果我注释掉newEndEventDate:
行,那么脚本运行正常。这只发生在IE10和IE的所有其他版本中。适用于Chrome和Firefox
答案 0 :(得分:1)
var rules = {
newEventDate: { required: true, regex: /^(19|20)\d\d-?(0[1-9]|1[012])-?(0[1-9]|[12][0-9]|3[01])$/ },
newEndEventDate: { required: true, regex: /^(19|20)\d\d-?(0[1-9]|1[012])-?(0[1-9]|[12][0-9]|3[01])$/ },
newEventText: { required: true, maxlength: 200 },
};
rules.newEndEventDate.greaterThan = rules.newEventDate;
var val = $("form").validate({
rules: rules,
messages: {
...
}
}).form();