我正在使用 JQuery Validate 插件来处理我的表单的验证。我需要在 2 个地方出现错误:
- 表格顶部
- 在现场级别
我让它在现场级别工作,但我如何让它在顶级和现场级别工作。
在表格的顶部,我想要这样的东西:
<p>You have the following error messages:</p>
<li>First Name - This is a required field</li>
<li>Last Name - This a required field</li>
<li>Email Address - This is a required field</li>
在表单级别,我显示了这样的错误消息,这是有效的:
First Name
This is a required field
[ ]
Last Name
This is a required field
[ ]
Email
This is a required field
[ ]
这是HTML代码
<html>
<body>
<div id="errormessages"></div>
<form id="myform">
<label for="firstname" class="required">First name</label> <input type="text" required="required" name="firstname" id="firstname" class="textInput" /></div>
<label for="lastname" class="required">Last name</label> <input type="text" required="required" name="lastname" id="lastname" class="textInput" /></div>
<label for="email" class="required">Email</label> <input type="text" required="required" name="email" id="email" class="textInput" /></div>
</form>
</body>
<html>
放置在表单级别的错误消息的 Jquery 代码:
$("#myform").validate({
rules: {
firstname: {
required: true
},
lastname: {
required: true
},
email: {
required: true
}
},
errorPlacement: function(error, element) {
error.insertBefore(element);
}
});
那么我将如何构建代码以在两个位置都有它呢?
谢谢干杯