1

我正在尝试使用 jQuery 验证插件来验证 jQuery UI 对话框中的名字和姓氏文本框输入。每次 JS 命中 $("#formEditName").valid(); 它只是炸弹。我错过了什么?

我的 HTML:

<div id="dialogName" title="Edit Name:">
<form class="formEditName" id="formEditName" method="get" action="">
    <p class="validateTips">
        All form fields are required.</p>
    <fieldset>
        <label for="firstName">
            First Name</label>
            <input type="text" name="firstName" id="firstName" value="" />
        <label for="lastName">
            Last Name</label>
             <input type="text" name="lastName" id="lastName" value="" />
        <label for="suffix">
            Suffix</label>
             <input type="text" name="suffix" id="suffix" value="" />
             <input class="submit" type="submit" value="Submit"/>
    </fieldset>
</form>
</div>

我的 JavaScript:

$('#formEditName').validate({
    rules: {
        firstName: "required"
    },
    {
    lastName: "required"
    }
});

$("#dialogName").dialog({
    autoOpen: false,
    resizable: false,
    width: 500,
    modal: true,
    show: {
        effect: "blind",
    },
    hide: {
        effect: "blind",
    },
            open: $(this).parent().appendTo(jQuery("#formEditName")),
    buttons: {
        "Update": function () {

                  if ($("#formEditName").valid()) {
                      alert("valid!");
                  } else {
                      alert("not valid");
                  }

    },
    Cancel: function () {
        $(this).dialog("close");
    }
    }
});
4

1 回答 1

1

尝试这个:

$('#formEditName').validate({
    rules: {
        firstName: "required",
        lastName: "required"
    }
});
于 2013-08-05T23:23:13.363 回答