我是非常新的使用JQuery验证插件来验证我的表格,但它不起作用。所有的ID都与脚本完全相同(CourseCode,CourseName等)。这段代码有什么问题吗?
<form id="courseForm" method="post">
<table>
<tr>
<td>
@if (ViewBag.Message != null)
{
<p>@ViewBag.Message</p>
}
</td>
</tr>
<tr>
<td>Code</td>
<td>
<input type="text" name="CourseCode" id="CourseCode" />
</td>
</tr>
<tr>
<td>Name</td>
<td>
<input type="text" name="CourseName" id="CourseName" />
</td>
</tr>
<tr>
<td>Creadit</td>
<td>
<input type="text" name="Creadit" id="Creadit" />
</td>
</tr>
<tr>
<td>Description</td>
<td>
<input type="text" name="Description" id="Description" />
</td>
</tr>
<tr>
<td>Department</td>
<td>
<select name="DepartmentId" id="DepartmentId">
@foreach (var department in allDepartments)
{
<option value="@department.Id">@department.DeptName</option>
}
</select>
</td>
</tr>
<tr>
<td>Semester</td>
<td>
<select name="SemesterId" id="SemesterId">
@foreach (var semester in allSemesters)
{
<option value="@semester.Id">@semester.SemesterName</option>
}
</select>
</td>
</tr>
<tr>
<td>
<input type="submit" value="Save" />
</td>
</tr>
</table>
</form>
这是验证脚本
$(document).ready(function () {
$("#courseForm").validate({
rules: {
CourseCode: {
required: true,
minlength: 5
},
CourseName: {
required: true,
},
Creadit: {
required: true,
range: [0.5, 5]
},
Description: {
required: true
}
},
messages: {
CourseCode: {
required: "Please enter a Course Code",
minlength: "Your username must consist of at least 5 characters"
},
CourseName: {
required: "Please provide a Course Name",
},
Creadit: {
required: "Please provide a Creadit",
range: "Your creadit Range must be at least .5 to 5 ",
},
Description: {
required: "Please provide a Description"
}
}
});
});
答案 0 :(得分:0)
尝试删除已安装的软件包,重新启动Visual Studio并安装更新的版本。我有类似的问题。