请帮助我进行验证,我一直在尝试自定义错误消息的显示位置,但我不能,我一直在尝试搜索网络,但似乎我不理解“errorLabelContainer”或 validate.js
我有两个输入,名称和电子邮件。我想控制消息显示的位置而不是输入标签下
<script>
jQuery(function($) {
$('#form').validate({
errorClass: "errorOne",
rules: {
firstname: {
required: true
},
email: {
required: true
}
},
messages: {
firstname: {
required: 'Please enter name',
errorElement : 'div',
errorLabelContainer: 'errorOne'
},
email: {
required: 'Please enter a valid email address',
errorElement : 'div',
errorLabelContainer: '.errorTwo'
}
}
});
</script>
<style>
.errorOne{
background: lightgreen;
min-height: 20px;
}
.errorTwo{
background: pink;
min-height: 20px;
}
</style>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery validation plug-in - main demo</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.1.js"></script>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.12.0/jquery.validate.js"></script>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.12.0/additional-methods.js"></script>
</head>
<body>
<form id="form" method="post" action="">
<div style="border:1px solid red; height: 500px">
<div class="col-md-8">
<label for="firstname">Enter Name:</label>
<input class="form-control" type="text" name="firstname" />
<label for="email">Enter Email:</label>
<input class="form-control" type="text" name="email" /><br>
<input type="submit" class="button" value="Submit" />
</div>
<div class="col-md-4">
<ul>
<li>
<p>The name error must be displayed in the div with class errorOne</p>
<div class="errorOne"></div>
</li>
<li>
<p>The email error must be displayed in the div with class errorTwo</p>
<div class="errorTwo"></div>
</li>
</ul>
</div>
</div>
</form>
</body>
</html>