Jquery验证不显示错误消息

时间:2013-11-22 20:14:12

标签: jquery jquery-validate

我开始使用jquery插件进行验证,并且很困惑为什么它不起作用,这是我的javascript代码: “

$(document).ready(function() {
    $('#shipper_form').validate({
        errorLabelContainer: "#errors",
        rules: {
            email: {
                required: true,
                email: true
            },
            business: "required",
            address: {
                required: true,
            },
            zipcode: {
                required: true,
            },
            phone: {
                required: true,
            },
            contact_name: {
                required: true,
            },
        },
        messages : {
            email : "Required Email *",
            business : "Required Business *",
            address : "Required Address *",
            zipcode : "Required Zip Code*",
            phone : "Required Phone*",
            contact_name : "Required Contact Name*",
        },
        submitHandler: function (form) {
            return false;
        }
    });
});
</script>"

形式:

<div id="errors"></div>
      <form method="post" action="signup.php">
        <table cellspacing="4" cellpadding="4">
            <tr>
                <td>
                    <input type="text" id="email" name="email" style="width: 300px;" class="form-control placeholder" placeholder="Email Address">
                    <span id="email_success" class="glyphicon glyphicon-check" style="color: green; display: none;"></span>
                </td>
            </tr>
            <tr>
                <td>

                    <input type="text" id="business" name="business" style="width: 300px;" class="form-control placeholder" placeholder="Business Name or DBA">
                    <span class="glyphicon glyphicon-check" style="color: green; display: none;"></span>
                </td>
            </tr>
         </table>
     </form>

错误消息显示电子邮件,但不是商业或任何其他的,我不知道我做错了什么。谢谢。

1 个答案:

答案 0 :(得分:3)

在我的情况下,验证无效,因为jquery.validate.js和jquery.validate.unobtrusive.js都已添加到页面中。在那种情况下,验证在一半的页面中工作,而在另一半中没有工作。(通过不工作我的意思;表单仍然得到正确验证,但没有显示错误信息。)

从页面中删除jquery.validate.unobtrusive.js解决了问题。