jquery - 错误 : Jquery form validate plug is appending duplicate error messages per field in firefox

标签 jquery html error-handling jquery-validate

在我的表单中,我使用 jquery form validate plugin验证表单。但问题是错误消息在每个字段下方多次显示。正如您在下面的屏幕截图中看到的那样。 这在 Chrome 中正常工作,但在 Firefox 中不正常。

enter image description here .

我发现这个错误发生在我使用字段 name="id"

<input name="id" class=""/>

我正在使用以下代码

$('document').ready(function(){
$("#form").validate({

    rules : {
        "id":{
            required:true,
            digits:true
        },

        "user_login":{
            required:true
        },

        "user_pass":{
            required:true
        }
        },
   messages: {
        "id":{
            required: "This field is required"
        },

        "user_login":{
            required: "This field is required"
        },

        "user_pass":{
            required: "This field is required"
        }
        },
   submitHandler: function(form){
        var formData = $('#form').serialize();
            $('#form').unbind("submit"); // fix for IE
            $.ajax({
                url: "",
                data:formData,
                type:"POST",
                error: function(error){
                },
                success: function(data) {
                }
            });
        return false;
      });
});

如何避免在每个字段中附加多条错误消息。

编辑:我的 HTML 代码是

<form id="form" name="" method="POST" action="">
<ul class="formstyle">
    <li>
        <label>Id</label>
        <input type="text" name="id" class="" />
    </li>
    <li>
        <label>User Login</label>
        <input type="text" name="user_login" class="" />
    </li>
    <li>
        <label>User Pass</label>
        <input type="text" name="user_pass" class="" />
    </li>    
    <li>
            <input type="submit"/>
    </li>
</ul>
</form>

最佳答案

在如下所示的表格标签内使用表单时,可能会发生同样的问题:

<table width="600">
<form id="form" name="" method="POST" action="">
... (rest of the table elements)
</form>
</table>

要解决此问题,您需要在表单标签内提供表格标签,如下所示:

<form id="form" name="" method="POST" action="">
<table width="600">
... (rest of the table elements)
</table>
</form>

希望这对您有所帮助。

关于jquery - 错误 : Jquery form validate plug is appending duplicate error messages per field in firefox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7832467/

相关文章:

google-app-engine - Golang - AppEngine Datastore GetMulti() 在返回 MultiError 时是否返回无效数据?

javascript - jQuery jsonp 缓存,有没有办法更改时间戳 url 键?

html - Div 高度根据内容自动调整

php - 如何在codeigniter中重置问题 “The page is not redirecting properly”?

html - Firefox Mobile 放大页面

html - 背景重复不起作用

asp.net-mvc - MVC捕获异常后在哪里可以找到错误信息

javascript - 尝试在导航中使用 jQuery 的 .addClass 方法

javascript - jquery - 使用 split 仅分割文本?

javascript - 如何在 Ajax 响应表中附加复选框