简体   繁体   English

如何找到未设置高度的动态创建的表格行元素的高度?

[英]How can I find the height of a dynamically created table row element with no height set?

I have two tables adjacent to each other both being populated dynamically in C#, I want both of these two tables to have the corresponding row height be exactly the same depending on what the first tables row height is (no specific height has been set, just needs to fit text in). 我有两个彼此相邻的表都在C#中动态填充,我希望这两个表都具有相同的行高,具体取决于第一个表的行高(未设置特定高度,只是需要添加文字)。

I have tried various ways of getting the height in C#, javascript, jquery, etc however they all return null or 0, i can get it to work by actively setting the height however this is not very effecient and occasionally buggy, is there a way I can get the height of a dynamically created html table row/cell? 我尝试了各种方法来获取C#,javascript,jquery等中的高度,但是它们都返回null或0,我可以通过主动设置高度来使其正常工作,但这不是很有效,有时还会出现问题,有没有办法我可以获取动态创建的html表行/单元格的高度吗?

@JoseRuiSantos comment is a better implementation if your design allows it (ie combine data in both tables in to a single table and accordingly render rows and columns to display as two different tables using css). 如果您的设计允许,@ JoseRuiSantos注释是一个更好的实现(即,将两个表中的数据合并到一个表中,并相应地使用CSS将行和列呈现为两个不同的表)。

One way I could think is to try using javascript: For this to work, do not set any table/row/column heights in both tables. 我可以想到的一种方法是尝试使用javascript:为使其正常工作,请不要在两个表中都设置任何表/行/列的高度。 Add an empty column at the end of each table with a div element in it. 在每个表的末尾添加一个空列,并在其中添加div元素。 In the page load completed event, identify the max column height in corresponding row of both tables and set the corresponding div element's (in both tables) height (in corresponding row) to the column max height. 在页面加载完成事件中,在两个表的相应行中标识最大列高度,并将相应的div元素(在两个表中)的高度(在相应行中)设置为列的最大高度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM