jQuery验证 - 验证具有相同名称和标识的多个表单

时间:2015-05-17 09:47:29

标签: jquery validation

我在此链接上使用了演示:http://runnable.com/UZJ24Io3XEw2AABU/how-to-validate-forms-in-jquery-for-validation

示例,我有jQuery检查验证:

$("#comment-reply-form").validate({

    // Specify the validation rules
    rules: {
        UserName: {
            required: true,
            minlength: 5
        },
        CommentContent: {
            required: true,
            minlength: 15
        },
    },

    // Specify the validation error messages
    messages: {
        UserName: {
            required: "input your name",
            minlength: "least 5 character"
        },

        CommentContent: {
            required: "input your comment",
            minlength: "least 15 character"
        },

    },

    submitHandler: function (form) {
        form.submit();
    }
});

我在循环foreach中有多个表单,所以如何具体检查"元素id"具体形式?

1 个答案:

答案 0 :(得分:3)

不应使用$("#comment-reply-form").validate(),而应使用:

$('form').each(function(){
    $(this).validate({
    )};
)};