我正在尝试使用 Jquery 验证具有 spring 标签的 spring mvc 表单,但此验证不起作用,需要紧急帮助。正在使用以下 JS 文件。
在检查时,我可以看到元素 id 传递了这些值,但验证和错误消息不起作用。请帮忙,因为我不太熟悉 Jquery。您的帮助将不胜感激。
<script type="text/javascript">
function submitForm()
{
$("#savelogin").validate({
rules:
{
UName:
{
required: true,
minlength: 6,
maxlength: 40
},
pwd:
{
equired: true,
minlength: 6,
maxlength: 40
}
},
messages:
{
UName:
{
required: "username is required!",
minlength: "username must be at least 6 characters long"
},
pwd:
{
required: "Please enter a password",
minlength: "Password must be at least 6 characters long"
}
},
submitHandler: function(form)
{
form.submit();
}
});
}
</script>
<title>Login Page</title>
</head>
<body>
<form:form commandName="userLogin" id="savelogin">
<fieldset>
<c:url value="/Registration.do" var="url"/>
<a href="<c:out value='${url}'/>">New User:Register</a>
<div>
<form:label path="userRegistration.userName" ><spring:message code="label.username"/> </form:label>
<form:input path ="userRegistration.userName" autocomplete="on" id="UName" />
<form:errors path="userRegistration.userName"></form:errors>
</div>
<div>
<form:label path="userRegistration.password"><spring:message code="label.password"/></form:label>
<form:password path="userRegistration.password" id="pwd"/>
<form:errors path="userRegistration.password"></form:errors>
</div>
<div>
<input type="submit" value="<spring:message code="label.login"/>" name="loginUser" id="submit" onclick="submitForm();"/>
</div>
</fieldset>
</form:form>
</body>
$(document).ready(function(){
$("#savelogin").validate({
rules:
{
UName:
{
required: true,
minlength: 6,
maxlength: 40
},
pwd:
{
equired: true,
minlength: 6,
maxlength: 40
}
},
messages:
{
UName:
{
required: "username is required!",
minlength: "username must be at least 6 characters long"
},
pwd:
{
required: "Please enter a password",
minlength: "Password must be at least 6 characters long"
}
},
submitHandler: function(form)
{
form.submit();
}
});
});
我试过这个,但什么也没发生。请检查并帮助。