Javascript 元素类型和类名的 Jquery 选择器?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7179526/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 01:12:27  来源:igfitidea点击:

Jquery Selector for Element type and Class name?

javascriptjqueryjquery-selectorscss-selectors

提问by Ocelot20

I have an element we'll call selectedTablethat contains this innerHtml:

我有一个我们称之为selectedTable包含这个的元素innerHtml

<TBODY>
    <TR>
        <TD></TD>
        <TD></TD>
        <TD class='ms-cal-nav-buttonsltr'></TD>
    </TR>
</TBODY>

I'm trying to use JQuery selectors to return the <TD>tag with the "ms-cal-nav-buttonsltr" class. I've found that $(selectedTable).find("TD")returns all the TD tags in the table as expected, but I'm wondering how I might go about combining the TDelement selector with a class selector. I've tried $(subnode).find("TD").find(".ms-cal-nav-buttonsltr")and $(subnode).find("TD .ms-cal-nav-buttonsltr")to no avail, but those were just shots in the dark. What's the most efficient way to accomplish this? Thanks in advance.

我正在尝试使用 JQuery 选择器返回<TD>带有“ms-cal-nav-buttonsltr”类的标签。我发现它$(selectedTable).find("TD")按预期返回了表中的所有 TD 标记,但我想知道如何将TD元素选择器与类选择器结合起来。我试着$(subnode).find("TD").find(".ms-cal-nav-buttonsltr")$(subnode).find("TD .ms-cal-nav-buttonsltr")无济于事的,但这些在黑暗中拍摄只。实现这一目标的最有效方法是什么?提前致谢。

回答by Dennis

Just concatenate the two:

只需将两者连接起来:

$(selectedTable).find("td.ms-cal-nav-buttonsltr");

the selectors you tried were looking for a .ms-cal-nav-buttonsltrelement underneath the td.

你试过选择正在寻找一个.ms-cal-nav-buttonsltr下面的元素td

回答by ksn

$('td.ms-cal-nav-buttonsltr', selectedTable);