I have the following jQuery code that detects if a user has clicked a search button but not typed anything in the text box, if so then they are focused on the textbox and the box turns red. What I want to do is when the user unfocuses (blur) from the textbox regar开发者_运维问答dless of whether they have entered text or not then the box will return to its original color, at the moment it stays red.
code:
$('#submit').click(function() {
if ( $('#q').val() == '' ) {
$('#q').focus().css('border-color', '#ff0000');
return false;
}
});
If I read you correctly:
$('#q').blur(function (){
$(this).css('border-color', '');
});
精彩评论