为什么jquery状态检查不起作用?
我试着使它在聚焦时颜色变为橙色以等待,然后当输入内容时它变为有效,因此变为绿色 然而,我似乎无法让它发挥作用为什么jquery状态检查不起作用?,jquery,Jquery,我试着使它在聚焦时颜色变为橙色以等待,然后当输入内容时它变为有效,因此变为绿色 然而,我似乎无法让它发挥作用 $('#listingnewform').focus( function(){ $('#listingnewform').css("border-bottom", "1px solid #C0AE31"); }); $('#listingnewform').blur( function(){ if ($('#listingnewforum').length) {
$('#listingnewform').focus( function(){
$('#listingnewform').css("border-bottom", "1px solid #C0AE31");
});
$('#listingnewform').blur( function(){
if ($('#listingnewforum').length) {
$('#listingnewform').css("border-bottom", "10px solid #fff");
}
else{
};
});
非常感谢您的任何帮助:)试试这个:
$('#listingnewform')
.focus(function() {
$(this).addClass('focused');
})
.blur(function() {
$(this).removeClass('focused');
})
.keyup(function() {
if ( $(this).val() ) {
$(this).addClass('valid');
} else {
$(this).removeClass('valid');
};
});
而不是通过css控制样式:
#listingnewform.focused {
border-bottom: 1px solid #C0AE31;
}
#listingnewform.valid {
border-bottom: 10px solid #fff;
}
请参见第1页:使用(此)引用您的班级或id
第二个:
$('#listingnewform')
.click(function() {
// when click check input empty or not
// if empty change border-bottom to yellow
if($(this).val() == ""){
$(this).css('border-bottom','3px solid yellow');
}
})
// when user start typing change border-bottom to red
.keydown(function() {
$(this).css('border-bottom','3px solid red');
})
// when keyup check for valid name and change border-bottom to green
.keyup(function() {
if($(this).val() == "admin"){
$(this).css('border-bottom','3px solid green');
}
})
// when focusout return border-bottom to input border
.focusout(function() {
$(this).css('border','1px solid black');
});
以下是提示:在发布javascript问题时始终使用它,这使其他人更容易看到问题