我有一些HTML,其中包含label
和input
字段:
<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>`
当label
- 验证失败时,我想用{name}的id
更改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",
},
}
});
答案 0 :(得分: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');
}
});
答案 1 :(得分:0)
$('.row').find('label[for=name]').css({"color": "red"});