JQuery重新定位错误消息

时间:2013-11-04 09:36:09

标签: javascript jquery

我有一个小问题。我想为我的密码检查重新定位我的错误消息。我想在我的表单按钮下看到该消息。所以我尝试设置一个errorLabelContainer,但它没有用,任何人都可以帮我解决问题吗?

HTML:

<form name="f" id="f" action="<%= request.getContextPath() %>/setpassword" method="POST">
    <table>
        <tr>
            <td>
                <label for="password">Passwort</label>:&nbsp;&nbsp;
            </td>
            <td>
                <input type="password" id="password" name="password" size="20" />
            </td>
        </tr>
        <tr>
            <td>
                <label for="password_again">Passwort wiederholen</label>:&nbsp;&nbsp;</td>
            <td>
                <input class="left" type='password' id="password_again" name="password_again" size="20" />


            </td>
        </tr>

        <tr>
            <td colspan="2">&nbsp;</td>
        </tr>
        <tr>
            <td colspan='2' align="center">
                <input name="submit" type="submit" value="submit" />
            </td>
        </tr>
    </table>

    <div class="errorMsg"> </div>
</form>

JQuery的:

$( "#f" ).validate({
      rules: {
        password: {
                required: true,
                minlength: 8
        },
        password_again: {
          equalTo: "#password"
        }
      }, 
      messages: {

        password: {
            required: "Bitte geben Sie Ihr Passwort zwei mal ein.",
            minlength: "Ihr Passwort muss aus mindestens 8 Zeichen bestehen."
            },

        password_again: {
            required: "Bitte geben Sie Ihr Passwort zwei mal ein.",
            equalTo: "Ihre Eingabe muss gleich sein."
            }
      },
      errorLabelContainer: '#errorMsg',
      wrapper: 'li'

});

感谢您的帮助:)

1 个答案:

答案 0 :(得分:2)

您的<div>包含 errorMsg,但您正在搜索 id errorMsg的元素。