Jquery - 动态更改表的行高。
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8981271/
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 - dynamically change a row height of a table.
提问by user1006072
I am using a Jquery's datatable. I have a table with id = "affectedRegion". It has a column with a radio button inside it. In part, some of the styling around this radio button cell gives each row it's height.
我正在使用 Jquery 的数据表。我有一个 id = "affectedRegion" 的表。它有一列,里面有一个单选按钮。部分地,围绕这个单选按钮单元格的一些样式赋予每一行它的高度。
In a special case, I have to hide the radio button column by doing something like this
在特殊情况下,我必须通过执行以下操作来隐藏单选按钮列
affectedRegion.fnSetColumnVis(0, false);
However, when I do this, the rows become much shorter than what I want. Since this code is shared at many other places, I would like to know if there is a way in Jquery that I can change the row height dynamically to maintain the same look and feel.
但是,当我这样做时,行变得比我想要的要短得多。由于此代码在许多其他地方共享,我想知道在 Jquery 中是否有一种方法可以动态更改行高以保持相同的外观。
I tried the below and it doesn't work.
我尝试了以下方法,但不起作用。
$("#affectedRegion").css('height', '25px');
Thanks for your help in advance.
提前感谢您的帮助。
回答by David Hoerster
I set up a simple jsFiddleto demo setting the row height of a table row, and it seems to work fine. I'm using Chrome, if that helps.
我设置了一个简单的jsFiddle来演示设置表格行的行高,它似乎工作正常。如果有帮助,我正在使用 Chrome。
I'm changing the height of the <tr>
tag, if that helps.
<tr>
如果有帮助,我正在更改标签的高度。
If you have other questions, let me know and I'll update my answer.
如果您还有其他问题,请告诉我,我会更新我的答案。
Good luck. Hope this helps.
祝你好运。希望这可以帮助。
UPDATEUpdated my fiddle here. If you have access to the index of the row to be resized, you can use jQuery's eq
function to only affect that table row in your table. I'm not sure if this helps or not, but this allows you to get away from having an id or some sort of marker class assigned to each row.
更新在这里更新了我的小提琴。如果您有权访问要调整大小的行的索引,则可以使用 jQuery 的eq
函数仅影响表中的该表行。我不确定这是否有帮助,但这使您可以避免为每一行分配一个 id 或某种标记类。
HTML
HTML
<table id='affectedRegions'>
<tr id='affectedRegion'>
<td>Hello</td>
<td>There</td>
</tr>
<tr id='affectedRegion2'>
<td>Hello</td>
<td>There</td>
</tr>
</table>
jQuery
jQuery
//change the height of the 2nd table row within #affectedRegions table
// eq() is zero-based.
$('#affectedRegions tr').eq(1).css('height', '200px');