Javascript-滚动div中的表

Javascript-滚动div中的表,javascript,html,scroll,Javascript,Html,Scroll,因此,我在滚动div中有一个表。现在,每次调整窗口的大小时,我都会调整div的大小,以允许用户看到尽可能多的表 function resizeTable() { document.getElementById('table-container').style.height = (window.innerHeight-60)+'px'; }; 唯一的问题是,有时表的高度会小于包含的div,因此在底部会浪费一些空间。因此,我希望div能够调整为窗口高度,除非表的高度小于窗

因此,我在滚动div中有一个表。现在,每次调整窗口的大小时,我都会调整div的大小,以允许用户看到尽可能多的表

function resizeTable() {
    document.getElementById('table-container').style.height = 
        (window.innerHeight-60)+'px';
};
唯一的问题是,有时表的高度会小于包含的div,因此在底部会浪费一些空间。因此,我希望div能够调整为窗口高度,除非表的高度小于窗口高度。我试过这个

function resizeTable() {
    var tableContainer = document.getElementById('table-container');
    var table = tableContainer.childNodes[0];
    if (table.offsetHeight < (window.innerHeight-60)) 
        { tableContainer.style.height = table.offsetHeight; }
    else 
        { tableContainer.style.height = (window.innerHeight-60)+'px'; }
};
function resizeTable(){
var tableContainer=document.getElementById('table-container');
var table=tableContainer.childNodes[0];
如果(表1.offsetHeight<(窗口内部高度-60))
{tableContainer.style.height=table.offsetHeight;}
其他的
{tableContainer.style.height=(window.innerHeight-60)+'px';}
};

…但它无法正常工作,随着时间的推移,窗口的大小不断调整,它会切断越来越多的表格。所以我来向您寻求帮助。

尝试使用
style.maxHeight
而不是
style.height