开发者

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜