javascript 如何使用 jQuery 获取表格中前两个 <tr> 的高度?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5177975/
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
How do I get the height of first two <tr> in a table using jQuery?
提问by Bluemagica
I need to display only the first two rows in a table, and on click on the div I need it to animate slideDownand show the full table. I could have just set displayto nonefor all the table rows except the first two, but that will ruin the effect when I want to show them all...so instead I figured I should use overflow:hidden, and set a height on the div based on the height of the first two rows of the table.... Any ideas how to do this?
我只需要在 a 中显示前两行,table单击 div 时我需要它来设置动画slideDown并显示完整的表格。我刚才设置display到none所有表行除了前两个,但会毁了效果时,我想告诉他们... ...所以不是我想我应该使用overflow:hidden,并设置基础上,对格的高度表格前两行的高度......任何想法如何做到这一点?
STRUCTURE:
结构体:
<div>
<table>
<tr>
<td>data</td>
</tr>
<tr>
<td>data</td>
</tr>
<tr>
<td>data</td>
</tr>
<tr>
<td>data</td>
</tr>
<tr>
<td>data</td>
</tr>
</table>
</div>
采纳答案by Hussein
回答by Harsh Baid
<div id="div-table">
<table>
<tr>
<td>data</td>
</tr>
<tr>
<td>data</td>
</tr>
<tr>
<td>data</td>
</tr>
<tr>
<td>data</td>
</tr>
<tr>
<td>data</td>
</tr>
</table>
</div>
Script will be:
脚本将是:
alert($('#div-table table tr').eq(0).height());
alert($('#div-table table tr').eq(1).height());
回答by Andy
$('tr:nth-child(1)>td, tr:nth-child(2)>td').css('height':100);

