我正在使用 jQuery validate ,它确实有效,这意味着它会显示错误并要求用户修复它们,但如果用户单击提交 - 它会毫无问题地提交。有人可以帮帮我吗 ?代码示例如下:
<form class="col-lg-2 well" id="filterForm">
<p><fmt:message key="name1"/></p>
<input id="name" type="text" placeholder="name" value="${searchBean.name}" name="name" class="input-large text-primary">
<p><fmt:message key="minimum.price"/></p><input id="minPrice" type="text" placeholder="minPrice" value="${searchBean.minPrice}" name="minPrice" class="input-large text-primary">
<p><fmt:message key="maximum.price"/></p>
<input id="maxPrice" type="text" placeholder="maxPrice" value="${searchBean.maxPrice}" name="maxPrice" class="input-large text-primary">
<p><fmt:message key="manufacturer1"/></p>
<input id="manufacturer" type="text" placeholder="manufacturer" value="${searchBean.manufacturer}" name="manufacturer" class="input-large text-primary">
<p>
<fmt:message key="categories"/>
<c:forEach var="cat" items="${requestScope.categories}">
<p><c:out value="${cat.second}"/></p>
<input type="checkbox" name="category" value="<c:out value="${cat.first}"/>"/>
</p>
</c:forEach>
<p><fmt:message key="sorts"/></p>
<select name="sort">
<option value="name"><fmt:message key="name"/></option>
<option value="manufacturer"><fmt:message key="manufacturer"/></option>
<option value="price"><fmt:message key="price"/></option>
</select>
<select name="sortType">
<option value="ASC"><fmt:message key="asc"/></option>
<option value="DESC"><fmt:message key="desc"/></option>
</select>
</p>
<p><fmt:message key="pagesize"/>
<input type="text" name="pageSize" id="pageSize" placeholder="pageSize" value="${searchBean.page.pageSize}">
</p>
<p><input type="submit" value="Filter" class="btn btn-primary"></p>
</form>
这是验证功能:
$('#filterForm').validate(
{
rules: {
name: {
maxLength: 50,
required: false
},
minPrice: {
required: validatePrices() == true,
min: 0,
digits: true
},
maxPrice: {
required: validatePrices() == true,
min: 1,
digits: true
},
manufacturer: {
maxLength: 50,
required: false
},
pageSize: {
required: true,
min: 0,
number: true
}
},
messages: {
name: {
maxLength:<fmt:message key="length.should.be.50.or.less"/>
},
minPrice: {
min:<fmt:message key="min.length.is.1"/>,
required:<fmt:message key="min.price.should.be.less.than.max"/>
},
manufacturer: {
maxLength:<fmt:message key="length.should.be.50.or.less"/>
},
maxPrice: {
min:<fmt:message key="min.length.is.1"/>,
required: validatePrices() == true
},
pageSize: {
min:<fmt:message key="min.length.is.1"/>
}
}
}
)
});
谢谢帮助。