0
我有以下幾點:jQuery的添加自定義的驗證
$('#qForm').validate({
rules: {
answerYesNo_1: { required:true } ,
answerYesNoText_1: { required: function(element) {
return $('#answerYesNo_1').val() == 'yes';
}
, isMoney: true },
answerYesNo_2: { required:true } ,
answerYesNoText_2: { required: function(element) {
return $('#answerYesNo_2').val() == 'yes';
}
, isMoney: true },
answerYesNo_3: { required:true } ,
answerYesNoText_3: { required: function(element) {
return $('#answerYesNo_3').val() == 'yes';
}
, isMoney: true },
answerYesNo_4: { required:true } ,
answerYesNoText_4: { required: function(element) {
return $('#answerYesNo_4').val() == 'yes';
}
, isMoney: true },
answerYesNo_5: { required:true } ,
answerYesNoText_5: { required: function(element) {
return $('#answerYesNo_5').val() == 'yes';
}
, isMoney: true }
},
...
jQuery.validator.addMethod("isMoney", function(value, element) {
alert(/^\$?[0-9][0-9\,]*(\.\d{1,2})?$|^\$?[\.]([\d][\d]?)$/.test(value));
return /^\$?[0-9][0-9\,]*(\.\d{1,2})?$|^\$?[\.]([\d][\d]?)$/.test(value);
});
我已經是它忽略了所需要的功能的第一部分的問題:
return $('#answerYesNo_1').val() == 'yes'
說:我選擇「不」 answerYesNo_2,回答YesNo_3,回答YesNo_4,回答YesNo_5,我會爲他們中的每一個獲得假。如果答案是否定的,則不應該進行isMoney驗證。任何幫助?
http://jsfiddle.net/k45w9/ – CFNinja