javascript中的表单验证可能无法正常工作 [英] Form validation in javascript does not work probably

查看:62
本文介绍了javascript中的表单验证可能无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理这个表格,假设在提交之前验证表格

I am working on this form which is suppose to validate the form before submitting

$(document).ready(function() {
    $("#form3").validate();
    if ($('#form3').valid()) $('#form3').submit();
});

但问题是:它在加载表单时打印(空字段错误)。

But the problem is: it prints the (empty fields error) when the form is loaded.

更新:该功能现在正在使用Horraaay :),代码如下:

UPDATE : the function is now working Horraaay :) with the following code:

      <script>
      $(document).ready(function(){
      $("#form3").validate();
     });
     </script>

唯一的问题是输入表单名称..我使用'submit'作为输入的名称然而,之前的形式是不同的名称。

The only problem was the input form name .. I used 'submit' as a name of the input form however before was on different name.

推荐答案

将您的代码放在表单提交事件上。这样的事情:

Put your code on the form submit event. Something like this:

$(document).ready(function()
{
    $("#form3").validate();
    $("#form3").submit(function(event)    
    {
        if (!$(this).valid()) 
        {
            event.preventDefault();
        }
    });
});

这篇关于javascript中的表单验证可能无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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