141

.clickテキストエリアが既にフォーカスされている場合、イベントがいつトリガーされるかを検出するにはどうすればよいですか?

私はこのjqueryを持っています:

$(".status").on("click","textarea",function(){
        if ($(this) == "focused") {
            // fire this step
        }else{
            $(this).focus();
            // fire this step
    }
4

4 に答える 4

1

JQuery を使用できる場合は、JQuery :focus セレクターを使用すると必要なことが行われます。

$(this).is(':focus');
于 2013-07-12T12:26:17.500 に答える
0

jQuery の.is( ":focus" )を使用する

$(".status").on("click","textarea",function(){
        if ($(this).is( ":focus" )) {
            // fire this step
        }else{
                    $(this).focus();
            // fire this step
    }
于 2013-07-12T12:25:27.270 に答える
0

試しましたか:

$(this).is(':focus');

Using jQuery to test if an input has focus を見てみましょう。さらにいくつかの例が紹介されています

于 2013-07-12T12:26:23.577 に答える