使用对象节点作为变量
Using a object node as a variable
如何像下面的 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();
在 newEndEventDate
中使用 newEventDate
给出错误 'newEventDate' is undefined
。但是,如果我注释掉 newEndEventDate:
行,那么脚本就可以正常工作。这只发生在 IE10 和可能所有其他版本的 IE 中。在 Chrome 和 Firefox
中工作正常
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();
如何像下面的 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();
在 newEndEventDate
中使用 newEventDate
给出错误 'newEventDate' is undefined
。但是,如果我注释掉 newEndEventDate:
行,那么脚本就可以正常工作。这只发生在 IE10 和可能所有其他版本的 IE 中。在 Chrome 和 Firefox
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();