0

我有以下代码:

<form id="reg_form_pay" class="fancy_form" action="" method="POST">
  <div class="wrap_input" style="margin-bottom: 10px;">
    <p class="inp_label">Firstname:</p>
    <i> </i>
    <input id="pay_firstname" type="text" value="" name="FirstName" style="width: 157px;">
  </div>
  <div class="wrap_input" style="margin-bottom: 10px;">
    <p class="inp_label">Surname:</p>
    <i> </i>
    <input id="pay_lastname" type="text" value="" name="Surname" style="width: 157px;">
  </div>
  <div class="wrap_input" style="margin-bottom: 10px; margin-top: 34px;">
    <p class="inp_label">E-mail:</p>
    <i> </i>
    <input id="pay_email" type="text" value="" name="Email" style="width: 157px;">
  </div>
  <div class="wrap_input" style="margin-top: 34px;">
    <p class="inp_label">Phone:</p>
    <i> </i>
    <input id="pay_phone" type="text" value="" name="PhoneNumber" style="width: 157px;">
  </div>
</form>

和验证:

$("#reg_form_pay").validate({
            rules: {
                Email: { required: true, email: true, checkEmail: true },
                PhoneNumber: { required: true, checkPhoneNumber: true },
                FirstName: { required: true },
                Surname: { required: true }
            }, 
        });

默认情况下,验证器label在验证为假时写入。我不想添加带有错误描述的元素。我想用 class 将类添加error到父divwrap_input。我怎么能告诉验证者这样做呢?
谢谢。

4

1 回答 1

1

将此添加到发送到的选项validate中将起作用:

showErrors: function(errorMap, errorList) {
    $.each(errorList,function(i,e){
        $(e.element).parents('.wrap_input').addClass('error');
    });                   
}

现场示例:http: //jsfiddle.net/nqp8J/

于 2012-08-22T09:11:21.337 回答