将 $(this) 连接到 jquery 选择器中的字符串

Concatenate $(this) to string in jquery selector

我正在尝试将 $(this) 连接到 jquery 选择器中的字符串,如下所示,但我的代码似乎不起作用:

    // when td is clicked
    $("body").on("click", "td" ,function() {

        if ( $(this + ' > .td_inputs').is(':hidden') ) {
            // 
        } 

    });

上面的代码有什么问题?

在 jQuery this 中引用 DOM 元素。

如果 .td_inputstd 的子项)被隐藏,如果您想以 jQuery 方式签入,那么您应该使用 .children() 方法:

// when td is clicked
$("body").on("click", "td" ,function() {

    if ( $(this).children('.td_inputs').is(':hidden') ) {
        // 
    } 

});

要重复使用 this,您正在寻找的通用格式是:

$("> .td_inputs", this)...

$(this).find("> .td_inputs")...

在 OP 的情况下,当您使用 > 时,您可以直接使用 .children 而无需 >,例如

$(this).children(".td_inputs")...