开发者

jquery validation rules - conditional?

In my jquery validation, is it possible to apply a certain rule only, for example, when the $_GET['name']); is Billybob?

here is a snippet of my rules:

    $("#form").validate({
        debug: false,
        rules: {
        semester: "required",
        courseno:
        {required: true,
        courseno: true},
        coursename: "required",
        "professor[]": "required",
        },

开发者_运维知识库for example, coursename is only required when Billybob is present.

Is that even possible?


Can't you do:

var options = {
    debug: false,
    rules: {
    semester: "required",
    courseno:
    {required: true,
    courseno: true},
    "professor[]": "required"
};
var coursename = <?php echo $name == 'BillyBob' ? 1 :  0; ?>;
if(coursename) {
    options.coursename = 'required';
}
$("#form").validate(options);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜