我无法让jQuery忽略某些字段。根据文件,一切都应该没问题,但事实并非如此。
默认设置和特定设置都设置为带有.ignore类的ingore元素:
$.extend($.validator, {
defaults: {
messages: {},
groups: {},
rules: {},
errorClass: "error",
validClass: "valid",
errorElement: "label",
focusInvalid: true,
errorContainer: $( [] ),
errorLabelContainer: $( [] ),
onsubmit: true,
ignore: ".ignore, :hidden",
ignoreTitle: false,
onfocusin: function(element, event) {
this.lastActive = element;
默认设置:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Login page</title>
<link class="row" href="<c:url value='/static/css/bootstrap.css' />"
rel="stylesheet">
<link class="row" href="<c:url value='/static/css/style.css' />"
rel="stylesheet">
<script type="text/javascript"
src="<c:url value='/static/js/jquery-2.2.0.js' />"></script>
<script type="text/javascript"
src="<c:url value='/static/js/bootstrap.js' />"></script>
<script type="text/javascript"
src="<c:url value='/static/js/jquery.validate.js' />"></script>
<script type="text/javascript" src="<c:url value='/static/js/jq.js' />"></script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div class="container">
<div class='row'>
<div class='jumbotron'>
<h1>Kamienica</h1>
<h3>Podaj login i hasło</h3>
</div>
</div>
<div class='row'>
<div class="login-container">
<div class="login-card ignore">
<div class="form ignore">
<c:url var="loginUrl" value="/login" />
<form action="${loginUrl}" method="post"
class="form-horizontal form ignore">
<c:if test="${param.error != null}">
<div class="alert alert-danger">
<p>Invalid username and password.</p>
</div>
</c:if>
<c:if test="${param.logout != null}">
<div class="alert alert-success">
<p>You have been logged out successfully.</p>
</div>
</c:if>
<div class="input-group input-sm">
<label class="input-group-addon ingore" for="email"><i
class="glyphicon glyphicon-user ignore"></i></label> <input type="text"
class="ignore form-control" id="email" name="email"
placeholder="Enter Username" required>
</div>
<div class="input-group input-sm ignore">
<label class="input-group-addon ingore" for="password"><i
class=" glyphicon glyphicon-lock ingore"></i></label> <input
type="password" class="form-control ignore" id="password"
name="password" placeholder="Enter Password" required>
</div>
<input type="hidden" name="${_csrf.parameterName}"
value="${_csrf.token}" />
<div class="form-actions">
<input type="submit"
class="btn btn-block btn-primary btn-default" value="Log in">
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
这是登录页面,出于显而易见的原因,我想关闭密码验证。作为绝望的行为,我开始在每个单元中插入“ignore”类,希望它最终能够工作:
$(window).on('resize', function(){
var win = $(this);
if (win.width() >= 992) {
$('#moveableFilter').prependTo('.left-bar');
} else if (win.width() < 992) {
$('#moveableFilter').prependTo('.mobile-top-bar');
}
});
如果你能指出我正确的方向,我将不胜感激。
此致 马修
答案 0 :(得分:0)
我认为您应该在ignore
上添加input
课程,而不是label
。
[更新]
你在使用jquery validation plugin吗?如果是,您应该只在html或js中设置验证规则。您在html元素中以及js规则中都有required
和min
等规则。我不确定会使用哪一个。但你应该只使用一种方式。
答案 1 :(得分:-1)
对不起,不好意思。我已经切换到最新插件,所有问题都解决了。
感谢您的帮助。
M