我在这里使用了一个解决方案(我在这里摆弄过)来限制提交表单,直到填写所有必填字段。
问题是当我在我的 MVC3 项目上运行时,正如我在 Firebug 上观察到的那样,它从以下块的第三行开始停止。因此,解决方案不起作用。
var validator = $("#myForm").validate();
var tabs = $("#tabs").tabs({
select: function(event, ui) { // Here.
// The following lines are not executed.
var valid = true;
var current = $(this).tabs("option", "selected");
var panelId = $("#tabs ul a").eq(current).attr("href");
有人可以告诉我为什么我的项目不会运行脚本的其余部分以及我应该做些什么来修复它?谢谢!
在我的视图文件中
@ModelType SLC.Models.RegisterModel
// downloaded with NuGet
<script src="@Url.Content("~/Scripts/jquery.validate.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.js")" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
var validator = $("#myForm").validate();
console.log(validator);
var tabs = $("#tabs").tabs({
select: function (event, ui) {
var valid = false;
var current = $(this).tabs("option", "selected");
var panelId = $("#tabs ul a").eq(current).attr("href");
$(panelId).find("input").each(function () {
console.log(valid);
if (!validator.element(this) && valid) {
valid = false;
}
});
return valid;
}
});
});
</script>
<link rel="stylesheet" href="@Url.Content("~/Content/themes/base/jquery-ui.css")" />
@Using Html.BeginForm("", "", Nothing, New With {.id = "myForm"})
@Html.ValidationSummary(True, "Account creation was unsuccessful. Please correct the errors and try again.")
@<div>
<div id="tabs">
<ul>
<li><a href="#tab-1">1. Information</a></li>
<li><a href="#tab-2">2. Information</a></li>
<li><a href="#tab-3">3. Confirm</a></li>
</ul>
<div id="tab-1">
// Some fields...
</div>
<div id="tab-2">
// Some fields...
</div>
<div id="tab-3">
// Some fields...
<input type="submit" value="Register" />
</div>
</div>
</div>
End Using
在我的布局模板文件中
<head>
<link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
// downloaded with NuGet
<script src="@Url.Content("~/Scripts/jquery-1.9.1.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery-ui-1.10.0.js")" type="text/javascript"></script>
</head>