我正在尝试使用jQuery Validation插件来验证jQuery UI对话框中的firstname和lastname文本框输入。每次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");
}
}
});
答案 0 :(得分:1)
试试这个:
$('#formEditName').validate({
rules: {
firstName: "required",
lastName: "required"
}
});