jQuery - way to find if form field is focused
Is there a way in jQuery to find out, if form filed is focused?
Like
if $('#id_here input[type=text]:focus'){ do this } else { }
开发者_StackOverflow中文版
?
Cheers, mart
Yes. Use focus
and blur
event handlers:
$("#id_here input:text").focus(function(e) {
// I am in focus, do something
alert("I am a " + e.target.tagName);
}).blur(function(e) {
// I have lost focus, do something else
});
精彩评论