我正在使用jQuery Validation插件,我想动态指定表单规则:
<input type="text" name="MyText" id="MyText" />
var Rule="Mytext";
$('#someForm').validate({
rules: {
Rule: {
required: true
}
},
messages: {
Rule: {
required: 'Please fill the MyText field'
}
}
});
答案 0 :(得分:3)
var Rule = "Mytext";
var validation = {rules: {}, messages: {}};
validation.rules[Rule] = {
required: true
};
validation.messages[Rule] = {
required: 'Please fill the MyText field'
};
$('form').validate(validation);