【发布时间】:2010-03-05 11:46:48
【问题描述】:
我正在尝试使用 JQuery 验证插件来验证输入字段。 数值范围 [range()] 取决于选择框的值。 For example when the select box is "A" the range should be between 1 and 10. But when its "B" it should be between 5 and 10 and so on.我确实尝试过读取选择框的值并调用一个函数来验证输入,传递最小值。
这可行,但是当您选择“A”并且您认为它应该是“B”时,它仍然验证为“A”。 我在考虑“取决于”,但我认为它只适用于“必需”。
$("#theSelectID").change(function () {
var theValueOfSelected = $('#LeverancierID :selected').text();
switch(theValueOfSelected){
case "A":
minval(1, "Null");
break;
case "B":
minval(5, "PRCC");
break;
}
function minval(theVal, theLev){
$("#AddInkoop").validate({
rules: {
Aantal: {
required: true,
range: [theVal, 999]
}
},
messages: {
Aantal:{
required:"required",
range: "give a number between "+ theVal +" and 999."
}
}
});
}
【问题讨论】: