0

我只是想检查来自 field 和 field1 的输入是否相同。但我不确定我的错误在哪里。

jQuery代码:

$(document).ready(function () {
    $('#f').validate({ 
        rules: {
            field: {
                nowhitespace: true, 
                minlength: 6,
                required: true
            },
            field11: {
                equalTo: "#field1",
                required: true
            }
        },
        messages: {
        field: {
                required: "required",
                minlength: "min 6."
            },
            field11: {
                required: "required",
            equalTo: "same as field."
            }
        },
        submitHandler: function (form) { 
            javascript:document.f.submit();
        }
    });
});

HTML:

<form name="f" action="/path/to/service" method="POST">
    <table>
        <tr>
            <td><label for="field">Field</label>:&nbsp;&nbsp;</td>
            <td>
                <input class="field" class="pw" type='field' id="field" name='field' size="20" />
            </td>
        </tr>
        <tr>
            <td><label for="field1">field 1</label>:&nbsp;&nbsp;</td>
            <td>
                <input class="field" class="pw" type='field1' id="field1" name='field1' 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>
</form>

谁能看到我的错误?谢谢任何帮助

4

2 回答 2

1

试试看rules

rules: {
        field: {
            nowhitespace: true,
            minlength: 6,
            required: true
        },
        field11: {
            equalTo: "#field",// Use "#field" in place of "#field1" 
            required: true
        }
    },

在你使用$ ('#f'). validate ({ like ,

<form name="f" id="f" action="/path/to/service" method="POST">

或者在没有id的情况下尝试,

$('form[name="f"]').validate({

读取equalTo方法

于 2013-10-21T10:24:10.260 回答
0

您将equalTo规则field设置为#field1- 它始终等于自身。其次,在您设置的规则中field11,实际名称是field1. 试试这个:

field1: {
    equalTo: "#field",
    required: true
}
于 2013-10-21T10:21:04.910 回答