我想添加一个带有条件的JQuery规则消息,表示条件x,显示messageX,如果是y,则显示messageY。
下面是我的代码:
addRuleAmount: function($element) {
$element.rules("add", {
ReqAmount : true, // function
validationAmount : true, // function
messages: {
ReqAmount : "Required Amount !!",
validationAmount : ($("#product_Type option:selected").attr('id') ==='car' ? "the amount must be between -100 and 100." : "the amount must be between 0 and 100.")
}
});
},发布于 2018-01-16 12:51:14
如果你正在使用一些静态关联,你可以考虑使用一个对象。
var messages = {
car: "The amount must be between -100 and 100.",
box: "The amount must be between 0 and 100.",
wrench: "The amount must be between 0 and 1."
};这为您提供了一种更具关联性的方法。所以你可以这样叫它:
addRuleAmount: function($element) {
$element.rules("add", {
ReqAmount : true, // function
validationAmount : true, // function
messages: {
ReqAmount : "Required Amount !!",
validationAmount : messages[$("#product_Type option:selected").attr("id")]
}
});
}https://stackoverflow.com/questions/48232214
复制相似问题