1

我正在为我的 jQuery 移动网站使用 jQuery Validation 插件。验证成功,但未显示错误消息。需要帮助找出问题所在。这是我的代码。

<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%; }
}
4

1 回答 1

11

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

    $("#theForm").removeData("validator")
    $("#theForm").removeData("unobtrusiveValidation");
于 2013-01-14T15:53:37.547 回答