如何选择包含类(jquery)的所有表行(tr)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5346084/
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-26 19:00:26  来源:igfitidea点击:

How to select all table rows (tr) that contained a class (jquery)

jquery

提问by blueDroid

I have a table (#tbLog) and need to select all table rows (tr) that contain a class called private.

我有一个表 (#tbLog),需要选择包含名为 private 的类的所有表行 (tr)。

Thanks

谢谢

回答by Bojangles

Simple enough:

足够简单:

$("#tbLog tr.private").action();

$("#tbLog tr.private").action();

If you have sub tables (why?), then use this instead to only select the top level trs

如果您有子表(为什么?),则使用它来仅选择顶级trs

$("#tbLog > tbody > tr.private").action();

$("#tbLog > tbody > tr.private").action();

Note that I've included tbodyin the selector as nearly all browsers will add this tag for you (it's part of the spec).

请注意,我已包含tbody在选择器中,因为几乎所有浏览器都会为您添加此标签(这是规范的一部分)。

回答by Phil

This how it's done:

这是如何完成的:

$('#tbLog tr.private')

回答by fl00r

This way?

这边走?

$("table#tbLog tr.private")

回答by Simon M

SCRIPT

脚本

$('#tbLog tr.private')

That should work...

那应该工作...

回答by RobertoBr

$("#tbLog").children("tr .private")

回答by EmCo

Try this code:

试试这个代码:

$('.private')

$('.private')

回答by Jhankar Mahbub

I like closest. if private is a class of element inside row

我喜欢最亲近的。如果私有是行内的一类元素

$("table#tbLog .private").closest('tr')

回答by Avi Kenjale

$("#myTable tr.pagging").click(function () { return false; });

$("#myTable tr.pagging").click(function () { return false; });

This is just in case you want to perform no action on tr click.

这是以防万一您不想对 tr click 执行任何操作。

回答by kruczy

I think parentwill work best assuming you want it to contain not be .private you can do

我认为parent最好假设你希望它包含不是 .private 你可以做

$("#tbLog tr .private").parent("tr")

this will give you an array of tr's if there is more than one satisfying the condition hope this helps

如果有多个满足条件,这将为您提供一系列 tr 希望这会有所帮助