代码之家  ›  专栏  ›  技术社区  ›  zod

如何重定向jquery验证成功的页面

  •  0
  • zod  · 技术社区  · 14 年前

    我正在使用jquery进行验证 制定一些规则。

    如果验证成功,我想重定向到另一个页面。 我该怎么做?

    // validate contact form on keyup and submit
    $("#contactForm").validate({
        //set the rules for the field names
        rules: {
            name: {
                required: true,
                minlength: 2
            },
            email: {
                required: true,
                email: 4
            },
    
        },
        //set messages to appear inline
        messages: {
            name: "Please enter your name",
            password: "Please enter your email"
        }
    
    });
    
    4 回复  |  直到 14 年前
        1
  •  1
  •   Community Egal    7 年前

    希望这能回答您的问题,而不是jquery特定的问题,但在验证完成后再调用它。

    How to redirect to another webpage in JavaScript/jQuery?

        2
  •  0
  •   Teja Kantamneni    14 年前

    在中添加重定向逻辑 submitHandler 回调。我想你想把 window.url 到不同的URL。正确的?

        3
  •  0
  •   Robert    14 年前

    呼叫 window.location.replace='http://www.newpage.com'; . 不特定于jquery。

        4
  •  0
  •   Vivin Paliath    14 年前

    尝试添加 submitHandler 选择权 validate 像这样:

    $("#contactForm").validate({
       ...
       submitHandler: function(form) {    
          window.location = "http://your.url.here";
       }   
    });
    

    所以当你验证表单时, 下议院议员 如果表单验证成功,并在那里重定向用户,则调用。