开发者

jQuery Unfocus / No Value

开发者 https://www.devze.com 2023-01-23 01:54 出处:网络
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 wan

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', '');
});
0

精彩评论

暂无评论...
验证码 换一张
取 消