如何使用jQuery或Javascript隐藏具有相同id的所有表行? [英] How do I hide all table rows with the same id using jQuery or Javascript?
问题描述
我有一个表格,其行具有彼此的自定义属性。我想使用jQuery(或Javascript)隐藏除父行之外的所有表行。我该怎么做呢?
I have a table with rows that have the of custom attribute with each other. I want to hide all the table rows except for the parent row using jQuery (or Javascript). How can I go by doing this?
<table>
<tr group="1">Parent</tr>
<tr group="1">Child</tr>
<tr group="1">Child</tr>
<tr group="1">Child</tr>
</table>
编辑:哇我的错字很大,我非常抱歉,我的意思是自定义属性。更新了!
Wow big typo on my part, I am terribly sorry, I meant custom attribute. Updated!
推荐答案
使用新的示例,可以使用jQuery的属性等于
选择器(此处)。看看这个美味的小提琴。
With your new example, it's possible using jQuery's atribute equals
selector (here). Take a look at this tasty fiddle.
基本上,在你的选择器中,你需要这个:
Basically, in your selector, you need this:
$(table tr [group ='2'])。hide()
当然,这是可自定义的。重要的是 tr [group ='2']
Of course, this is customisable. The important bit is tr[group='2']
编辑
这个更新的小提琴应该有效。如果有人可以发布更好的方式,请执行。
This updated fiddle should work. If someone can post a better way, please do.
它添加到上面的行:
$(table tr [group ='2'])。filter(:not(:first))。hide();
这篇关于如何使用jQuery或Javascript隐藏具有相同id的所有表行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!