页面加载jQuery后匹配div高度

页面加载jQuery后匹配div高度,jquery,image,height,match,Jquery,Image,Height,Match,加载图像后,我无法匹配div的高度。它获取最高div的高度,但似乎在加载图像之前就获得了该高度。这有什么办法吗?以下是我到目前为止的情况: function matchColHeights(col1, col2) { var col1Height = $(col1).height(); alert('col1 '+col1Height); var col2Height = $(col2).height(); alert('col2 '+col2Height);

加载图像后,我无法匹配div的高度。它获取最高div的高度,但似乎在加载图像之前就获得了该高度。这有什么办法吗?以下是我到目前为止的情况:

function matchColHeights(col1, col2) {
    var col1Height = $(col1).height();
    alert('col1 '+col1Height);
    var col2Height = $(col2).height();
    alert('col2 '+col2Height);

    if (col1Height < col2Height) {
        $(col1).height(col2Height);

    } else {
        $(col2).height(col1Height);
    }
}

$(document).ready(function() {
    matchColHeights('#leftPanel', '#rightPanel');
});
函数匹配colheights(col1、col2){
var col1Height=$(col1.height();
警报('col1'+col1高度);
var col2Height=$(col2.height();
警报('col2'+col2Height);
if(col1Height
这里有一个指向运行它的位置的链接:

根据,
窗口。加载所有图像时会触发加载,因此请尝试以下操作:

$(window).load(function() {
  // ...
}
根据,当加载所有图像时,
window.load
被激发,因此请尝试以下操作:

$(window).load(function() {
  // ...
}

加载图像后,是否调整列高。比如:

$('img').load(function() {
     $(col1).height(col2Height);
});

加载图像后,是否调整列高。比如:

$('img').load(function() {
     $(col1).height(col2Height);
});

问题在于图像标签上没有提供宽度和高度。DOM使用它们进行测量,如果没有提供,则必须等待图像加载,以便“重新绘制”具有正确高度的屏幕。这就是它不起作用的原因。

问题在于图像标签上没有提供宽度和高度。DOM使用它们进行测量,如果没有提供,则必须等待图像加载,以便“重新绘制”具有正确高度的屏幕。这就是它不起作用的原因。

我试过这个,它似乎没有抓住div的高度。我做了一个警告,它甚至没有弹出。我试过这个,它似乎没有抓住div的高度。我做了一个警报,它甚至没有弹出。通过一点拨弄,我让这个工作,谢谢!这就是我的工作原理:函数matchColHeights(col1,col2){$('img').load(函数(){var col1Height=$(col1.height();alert('col1:'+col1Height);var col2Height=$(col2.height();alert('col2:'+col2Height);if(col1Height