jQuery验证不显示消息

时间:2012-06-25 01:18:12

标签: jquery-mobile jquery-validate

我正在使用jQuery Validation插件,用于我的jQuery移动网站。验证正在进行,但它没有显示错误消息。找出问题所在需要帮助。这是我的代码。

<script language="javascript" type="text/javascript" >
    $(document).ready(function () {
        $("#LoginForm").validate();
    });
</script>




<form id="LoginForm" class="validate" action="~/Home/Search" method="get">
<ul data-role="listview" data-inset="true">
    <li data-role="list-divider"><div class="center-wrapper">Secure Login</div></li>

     <li data-role="fieldcontain">
        <label for="FirmKey">FirmKey</label>
        <input type="text" id="FirmKey" name="FirmKey" class="required" />
    </li>

    <li data-role="fieldcontain">
        <label for="UserName">User Name</label>
        <input type="text" id="UserName" name="UserName" class="required" />
    </li>

    <li data-role="fieldcontain">
        <label for="Password">Password</label>
        <input type="password" id="Password" name="Password" class="required" />
    </li>

    <li data-role="fieldcontain">
        <input type="submit" id="submit" value="LOGIN" />
    </li>
</ul>
</form>

CSS:

label.error {
    float: none; 
    color: red; 
    font-size: 16px;
    font-weight: normal;
    line-height: 1.4;
    margin-top: 0.5em;
    width: 100%;
    display: block;
    margin-left: 22%;
}

@media screen and (orientation: portrait){
    label.error { margin-left: 0; display: block; }
}
@media screen and (orientation: landscape){
    label.error { display: inline-block; margin-left: 22%; }
}

1 个答案:

答案 0 :(得分:10)

如果您碰巧包含了jquery.validation.unobtrusive脚本,那么在您有机会之前,它将.validate()您的表单。您需要从表单中删除自动添加的验证对象,然后才能手动调用.validate()以使其正常运行...

    $("#theForm").removeData("validator")
    $("#theForm").removeData("unobtrusiveValidation");