jQuery验证 - 多提交一份asp.net表单上的按钮,不同的验证组? [英] jQuery Validation - Multiple submit buttons on one asp.net form, different validation groups?

查看:175
本文介绍了jQuery验证 - 多提交一份asp.net表单上的按钮,不同的验证组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个登录段和段寄存器一个asp.net的形式。这里有两个提交对应于相应部分的按钮,登录或注册。我使用jQuery验证,但是我无法找到一个方法来指定验证组,我会与正常asp.net验证。当我点击注册按钮,现在它是要求在填写登录字段。任何人有什么想法?谢谢!

I have an asp.net form with a login section and a register section. There are two submit buttons that correspond to the appropriate section, login or register. I am using jquery validation, however I cannot find a way to specify validation groups as I would with normal asp.net validation. When I click the register button, right now it is asking for the login fields to be filled in. Anyone have any thoughts on this? THANKS!

推荐答案

我猜你正在使用此验证插件: jQuery验证。该插件使用表单标签作为验证组,这样来完成你想,你需要取决于哪个按钮,用户按下删除的规则是什么。此外,您将需要添加规则,回哪里验证失败,则该用户决定点击另一个按钮的情况。

I'm guessing you are using this validation plugin: JQuery Validation . The plugin uses the form tag as a validation group so to accomplish what you want you will need to remove rules depending on which button the user pushes. Also, you will need to add the rules back for the case where the validation fails then the user decides to click the other button.

下面是一个例子:

$(document).ready(function()
{
    $("#form").validate({
        invalidHandler: addRules 
    });        

    addRules();        

    $("#submit1").click(function(){
        $(".group2").each(function(){
            $(this).rules("remove");
        });
    });
    $("#submit2").click(function(){
        $(".group1").each(function(){
            $(this).rules("remove");
        });
    });

});
var addRules = function(){
    $("#input1").rules("add", {required:true});
    $("#input2").rules("add", {required:true});
}

这个方法可以让你的类属性(1或组2)添加到您的每一个输入充当验证组。

This approach allows you to add a class attribute (group1 or group2) to each of your inputs which acts as a validation group.

这篇关于jQuery验证 - 多提交一份asp.net表单上的按钮,不同的验证组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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