我有一个JSP如下:
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<script src="${pageContext.request.contextPath}/jquery/jquery.js"></script>
<script src="${pageContext.request.contextPath}/jquery/jquery.validate.min.js"></script>
<script type="text/javascript" language="JavaScript">
jQuery(document).ready(function () {
//......
....///
$("#apiID").validate({
rules: {
pinNbr: "required",
TranDt: "required"
},
messages: {
pinNbr:"Please enter a Pin number.",
TranDt: "Please enter tran date."
}
});
$("#resetId").click(function () {
var validator = $('#apiID');
validator.resetForm();
});
});
</script>
<form:form id="apiID" action="executeApi.do" commandName="apiForm">
//..
<DIV class="label">Pin Number: </DIV><DIV class="nonLabel"><form:input path="pinNbr" maxlength="50" size="40" /></DIV>
<DIV class="label">Todays Transaction: </DIV><DIV class="nonLabel"><form:input path="TranDt" size="10" maxlength="10" />
..//
<DIV class="btn-group">
<button id="submitId" type="submit" class="default-button">Submit
</button>
<button id="resetId"
type="reset" class="default-button">Reset
</button>
</DIV>
</form:form>
当我没有输入pinNUmber和TranDt的值时,我会使用validate()获取输入字段内联的错误消息。一旦点击重置我想要内联错误消息消失。 resetForm()重置所有输入字段按钮中的值,但不重置错误消息。按钮重置会重置路径变量,但不会重置这些错误消息。
答案 0 :(得分:1)
试试这个:
form.find('label.error').remove();
更新1:
尝试在validator.resetForm();
form.find(".error").removeClass("error");