jQuery 部分选择器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1368591/
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
jQuery Partial Selectors
提问by CLiown
I have a number of tables, which have nested tables. I using jQuery to hide some of the table cells as a number are empty or the contents irrelevant.
我有许多表,其中有嵌套表。我使用 jQuery 来隐藏一些表格单元格,因为数字为空或内容不相关。
I use jQuery to hide all TD's and then jQuery to show them, for instance, if they contain a <P>
.
我使用 jQuery 来隐藏所有 TD,然后使用 jQuery 来显示它们,例如,如果它们包含<P>
.
Unfortunately some of the TD's don't contain anything but still need to be shown. The class the TD's are given is dynamic so I wont be able to code for them all (Sensibly) however they do all end 'Node'
不幸的是,有些 TD 不包含任何内容,但仍需要显示。TD 给出的类是动态的,所以我将无法为它们全部(明智地)编码,但是它们都以“节点”结尾
I was wondering if its possible to do something like...
我想知道是否有可能做这样的事情......
$(function() {
$('TR .*Node').css('display','inline');
});
回答by Eric
This will select any tds with Node
somewherein their class name.
这将选择在其类名中Node
某处的任何 tds 。
$('td[class*=Node]').css('display','inline');
This will select any tds with Node
at the end oftheir class name.
这将选择任何以类名Node
结尾的tds 。
$('td[class$=Node]').css('display','inline');
Bear in mind that .show()
does roughly the same thing as .css('display','inline');
请记住,.show()
这与.css('display','inline');
回答by tvanfosson
The [attribute$="value"]selector will let you match attributes that end with a particular value. Note that using show()
instead of changing the CSS directly will retain the display characteristics of the element you are revealing. If you really want to force them to display inline, you can revert it back to the css method with display: inline
在[属性$ =“值”]选择将让你匹配属性为此与一个特定的值。请注意,使用show()
而不是直接更改 CSS 将保留您正在显示的元素的显示特性。如果您真的想强制它们显示内联,您可以将其恢复为 css 方法display: inline
$('td[class$="Node"]').show();
回答by kaiz.net
$(function() {
$('td[class*=Node]').css('display','inline');
});