Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/462.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jquery height()方法返回行高度_Javascript_Jquery_Css - Fatal编程技术网

Javascript jquery height()方法返回行高度

Javascript jquery height()方法返回行高度,javascript,jquery,css,Javascript,Jquery,Css,我有下面的函数,其中有三列。javascript应该找到最大的列,并将其他列的高度设置为该高度 $(document).ajaxComplete(function(){ function fixScheduleHeights(){ content1 = $('.schedule_content_holder').first(); content2 = content1.next(); content3 = content2.next();

我有下面的函数,其中有三列。javascript应该找到最大的列,并将其他列的高度设置为该高度

$(document).ajaxComplete(function(){
    function fixScheduleHeights(){
        content1 = $('.schedule_content_holder').first();
        content2 = content1.next();
        content3 = content2.next();

        content1Height = content1.height();
        content2Height = content2.height();
        content3Height = content3.height();

        biggestScheduleHeight = Math.max(content1Height, content2Height, content3Height);

        $('.schedule_content_holder').height(biggestScheduleHeight);
    }
    fixScheduleHeights();
});
我尝试了上面的代码,如果最大的一列是第一列,它就会工作。如果最长的列是第二列,则不起作用。出于调试目的,我插入了以下代码:

alert(content2height);
它警告值16,它不应该是content2height的值。在查看inspector之后,我发现问题在于body有一个css属性line height:16px


为什么content2Height=16?我如何更改它使其等于实际高度?

有一种更简单、最健壮的方法来执行您正在执行的操作,它不依赖于列的位置或数量,因为我认为您对
.next()
的调用不会返回您认为返回的内容
next()
返回DOM树中的下一个同级(可选地由选择器过滤,但您不提供)。您可以返回一个

、一个
或其他任何内容

$(document).ajaxComplete(function(){
    var $columns = $('.schedule_content_holder');
    var maxHeight = 0;

    $columns.each(function() {
         maxHeight = Math.max(maxHeight, $(this).height());
    });

    $columns.height(maxHeight);
});

.schedule\u content\u holder
是内联元素吗?
height()
不返回行高,所以如果它说是16px,那么它就是16px。还要注意的是,所有变量都是globalalmost似乎没有加载ajax要加载的内容。是否确定
content1.next()
正在返回下一列?你能发布你的标记吗?样式对高度有很大的影响,你真的需要发布一些HTML和CCS(最好是在JSFIDLE中)。