0

我有一些 HTML 有一个labelinput这样的字段:

<div class="table-cell segmented">
    <label for="email" class="field-label">email</label>
    <input id="email" name="email" class="required" type="email" placeholder="Required"  />
    <input type="hidden" id="forgotPasswordInput" name="forgotPasswordInput" value="false"/>
</div>`

当-validation 失败时,我想labelid“名称”更改颜色。如果验证失败input,我不需要更改添加的标签的颜色。input

我有以下方法来验证:

var validator =$("#loginForm").validate({ 
            rules: { 
                email: {
                    required:true,
                    email:true,
                    emailRule: true,
                },
                emailPass: {
                    required:true,          
                },
            }, 
            messages: { 
                email: {
                    required:"enter email",
                    email:"invalid email",
                },
                emailPass:{
                    required:"enter password",
                },
            }       
        });
4

2 回答 2

0

我认为您需要使用 invalidHandler 方法。

var validator =$("#loginForm").validate({
  rules: {
    email: { required:true, email:true, emailRule: true, },
    emailPass: { required:true,}
  },
  messages: {
    email: { required:"enter email", email:"invalid email", },
    emailPass:{ required:"enter password", }
  },
  invalidHandler: function (ev, validator) {
    $('select your label').css('color', 'the new color');
  }
});
于 2013-10-02T23:30:43.797 回答
0
$('.row').find('label[for=name]').css({"color": "red"});
于 2013-10-02T23:31:01.267 回答