简体   繁体   English

调整表和div大小的Javascript

[英]Javascript to resize table AND div inside

I have a table and a div in it. 我有一张桌子和一个div。 I have to resize both on load and on window resize. 我必须在加载和窗口调整大小时都调整大小。

These Javascript functions (resizeTable and resizeDiv) work if called separately, but resizeDiv doesn't work if called after resizeTable from autoResize. 如果分别调用这些Javascript函数(resizeTable和resizeDiv),则它们起作用,但是,如果从autoResize中的resizeTable之后调用,则resizeDiv不起作用。

<script>

function autoResize()
{
    var windowSize = document.documentElement.clientHeight;
    var tableHeight = windowSize * 0.9+'px';
    var rowHeight = (windowSize * 0.9 - 99 - 50)+ "px";
    resizeTable(tableHeight);
    resizeDiv(rowHeight);
}

function resizeTable(tableHeight)
{
    document.getElementById("mainTable") = tableHeight;
}

function resizeDiv(rowHeight)
{
    document.getElementById("cellLogin").style.height = rowHeight;
}

</script>

Well, I think you've got a bit of a mistake in your code. 好吧,我认为您的代码中有一些错误。 The line: 该行:

document.getElementById("mainTable") = tableHeight;

Should actually be: 实际上应该是:

document.getElementById("mainTable").style.height = tableHeight;

Here's a JSFiddle with the fixed code, seems to give you what you need. 这是带有固定代码的JSFiddle ,似乎可以为您提供所需的东西。 Let me know if you have any questions! 如果您有任何疑问,请告诉我!

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

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