jQuery hide< tr>基于< td> ID [英] JQuery hide <tr> based on <td> id

查看:153
本文介绍了jQuery hide< tr>基于< td> ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想根据表格数据ID从我的表格中隐藏一些表格行,我只找到了基于表格数据值隐藏表格行的方法,但是(在我的情况下)这不是解决方案.

I would like to hide some table row from my table based on the table data id, I've only found ways to hide the table row based on the table data value but that is (in my case) not the solution.

例如,可以说这是我的桌子:

For example, lets say this is my table:

<table id='table1' border="1">
<tr id='hideme'>
<td id='letmehide'>row 1, cell 1</td>
<td id='letmehide'>row 1, cell 2</td>
</tr>
<tr id='donthideme'>
<td id='dontletmehide'>row 2, cell 1</td>
<td id='dontletmehide'>row 2, cell 2</td>
</tr>
</table>

我的javascript/JQuery应该是什么样的? 小提琴: http://jsfiddle.net/twyqS/

What should my javascript/JQuery look like? Fiddle: http://jsfiddle.net/twyqS/

推荐答案

请考虑到id在页面上必须是唯一的,所以我建议您使用css类代替ids

Take into account that ids must be unique on your page so I recommend you to use css classes instead of ids

HTML

<table id='table1' border="1">
<tr class='hideme'>
<td class='letmehide'>row 1, cell 1</td>
<td class='letmehide'>row 1, cell 2</td>
</tr>
<tr class='donthideme'>
<td class='dontletmehide'>row 2, cell 1</td>
<td class='dontletmehide'>row 2, cell 2</td>
</tr>
</table>

JS

$('#table1 .hideme').hide();

这将允许您在必要时隐藏几行.

This would allow you to hide several rows if necessary.

这篇关于jQuery hide&lt; tr&gt;基于&lt; td&gt; ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆