http://docs.jquery.com/Plugins/Validation” rel=“nofollow” 验证原始,以验证两种需要但只有一个错误信息才能显示的选箱:
Java:
$( form ).validate({
groups: {
cardExpiration: card_expirationMonth card_expirationYear
},
rules: {
card_expirationMonth: required ,
card_expirationYear: required
},
errorPlacement: function (error, element) {
if (element[0].name === card_expirationMonth || element[0].name === card_expirationYear ) {
error.prependTo( form );
}
}
});
标记:
<form method="post" action="/wherever">
<div class="-field field-expirationMonth">
<select name="card_expirationMonth" id="card_expirationMonth">
<option value="">MM</option>
<option value="01">01</option>
<option value="02">02</option>
<option value="03">03</option>
<option value="04">04</option>
<option value="etc">Etc</option>
</select>
</div>
<div class="-field field-expirationYear">
<select name="card_expirationYear" id="card_expirationYear">
<option value="">YY</option>
<option value="2012">12</option>
<option value="2013">13</option>
<option value="2014">14</option>
<option value="2015">15</option>
<option value="etc">Etc</option>
</select>
</div>
</form>
似乎把错误信息混为一谈,这样就只能看一看,但似乎采取的做法是,集团中只有一个领域需要......任何想法?