.click如果 textarea 已经聚焦,如何检测何时触发事件?
我有这个jQuery:
$(".status").on("click","textarea",function(){
        if ($(this) == "focused") {
            // fire this step
        }else{
            $(this).focus();
            // fire this step
    }
.click如果 textarea 已经聚焦,如何检测何时触发事件?
我有这个jQuery:
$(".status").on("click","textarea",function(){
        if ($(this) == "focused") {
            // fire this step
        }else{
            $(this).focus();
            // fire this step
    }
使用纯 JavaScript:
this === document.activeElement // where 'this' is a dom object
或使用 jquery 的:focus伪选择器。
$(this).is(':focus');
如果您可以使用 JQuery,那么使用JQuery :focus 选择器就可以了
$(this).is(':focus');
使用 jQuery 的.is( ":focus" )
$(".status").on("click","textarea",function(){
        if ($(this).is( ":focus" )) {
            // fire this step
        }else{
                    $(this).focus();
            // fire this step
    }