Javascript 如何使用jQuery设置内容高度–;剪成小窗口大小

Javascript 如何使用jQuery设置内容高度–;剪成小窗口大小,javascript,jquery,window,height,Javascript,Jquery,Window,Height,我很难让它工作。目前,它正在将节[role=“main”]调整到适当的高度,但当您将窗口调整到较小的大小时,它将被截断 <script type="text/javascript"> $(function(){ $('section[role="main"]') .css({'height': (($(window).height()))+'px'}); $(window).resize(function(){ $('s

我很难让它工作。目前,它正在将节[role=“main”]调整到适当的高度,但当您将窗口调整到较小的大小时,它将被截断

<script type="text/javascript">
    $(function(){
        $('section[role="main"]') .css({'height': (($(window).height()))+'px'});
        $(window).resize(function(){
            $('section[role="main"]') .css({'height': (($(window).height()))+'px'});
        });
    });
</script>

$(函数(){
$('section[role=“main”]).css({'height':(($(window.height())+'px'});
$(窗口)。调整大小(函数(){
$('section[role=“main”]).css({'height':(($(window.height())+'px'});
});
});
我还想知道如何补偿页脚的高度?到目前为止,它正在将页脚从屏幕上推出

谢谢你的帮助

所以它应该是这样的,帕特里克(更新)

    <script type="text/javascript">
        $(function(){
            $(window).resize(function(){
                var winheight = $(window).height();
                var heightMinusFooter = winheight - jQuery("#footer").height();
                $('section[role="main"]') .css({'height': heightMinusFooter+'px'});
            });
        });
    </script>

$(函数(){
$(窗口)。调整大小(函数(){
var winheight=$(window.height();
var heightMinusFooter=winheight-jQuery(“#footer”).height();
$('section[role=“main”]).css({'height':heightMinusFooter+'px'});
});
});

从窗口高度减去页脚高度,然后应用

$(window).resize(function(){
    var winheight = $(window).height();
    var heightMinusFooter = winheight - jQuery("#footer").height();
    $('section[role="main"]') .css({'height': heightMinusFooter+'px'});
});

我已经包括了我是如何做到这一点只是为了确认,还没有它的工作相当。是否正确?是否必须在CSS中指定页脚的高度?当我尝试时,它似乎没有帮助。获取高度的变量必须在resize函数中,并且您正在使用jQuery('footer'),因为没有名为footer的标记,所以jQuery('footer')不起作用,请为页脚使用的任何元素指定一个类似于“footer”的id,并使用jQuery('footeridthayouused')不,您不必指定高度,.height调用将获取元素的计算高度,并且您不使用最小高度使用高度或最大高度。谢谢。我很感谢你的帮助——仍然没有完全发挥作用。我已经在我的帖子中更新了代码。。。对吗?很抱歉我不是很精通jQuery。