jQuery多种表单验证 [英] jQuery multiple form validation

查看:91
本文介绍了jQuery多种表单验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在不同的页面中有多种形式,有没有办法写一个single function来处理validation或应该为每种形式的代码separately编写代码.

I have multiple forms in different page, Is there a way to write a single function which would take care of validation or should i write code for each form separately.

$(document).ready(function () {   
    $('#fvujq-form1').validate();
    $('#fvujq-form2').validate();
});

注意:每种表单都有自己的规则.

Note: Each form has its own rules.

更新:

$("form").each(function () {
        $(this).validate({

            rules: {

                username: {
                    required: true
                },
                password: {
                    required: true
                },
                name: {
                    required: true,                        
                },
                cperson: {
                    required: true,                       
                }
            },
            submitHandler: function (form) {
                return false; //temporarily prevent full submit
            }
        });
    });

现在,不同页面中的usernamepassword格式不同,并且nameperson的格式也不同.以这种方式提交普通表单是否正确?

Now the username and password of different form and name and person is of different form in different page. Is it right to proceed in this way of having a common form submission.

推荐答案

如果需要的话,可以使用$("form")选择器来验证type类型的所有元素.不过,我不建议您专门针对具有多种形式的页面.

You can use the $("form") selector to validate all elements of type form if that's what you are asking for. I would not recommend that specifically for a page with multiple forms though.

这篇关于jQuery多种表单验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆