0

すべての列 ( 、および)ifの高さを等しくするために、いくつかの文を作成しました。ただし、何らかの理由で関数を使用して値を取得できますが、 other から取得した値を設定しようとすると機能しません。#col1#col2#col3.css()var

これは私のjqueryコードです:

$(document).ready( function(){
    var col1_height = $('#col1').css('height');
    var col2_height = $('#col2').css('height');
    var col3_height = $('#col3').css('height');

    if (col1_height < col2_height){
        $('#col1').css('height', col2_height);
    }

    if (col1_height < col3_height){
        $('#col1').css('height', col3_height);  
    }

    if (col2_height < col1_height){
        $('#col2').css('height', col1_height);
    }

    if (col2_height < col3_height){
        $('#col2').css('height', col3_height);
    }

    if (col3_height < col1_height){
        $('#col3').css('height', col1_height);
    }

    if (col3_height < col2_height){
        $('#col3').css('height', col2_height);
    }
});

これが私のjsfiddleです:http://jsfiddle.net/Arkl1te/aNcYC/

4

2 に答える 2

2

これを使って:

var newHeight = 0;
$('#col1, #col2, #col3').find('.content').each(function(){
    var temp = $(this).height();
    newHeight = temp > newHeight ? temp : newHeight;
}).css('height', newHeight);

これは各列をループし、.content各要素の高さを と比較しnewHeightます。newHeight現在の高さがそれより大きい場合、newHeightこの値に設定されます。

ループが終了すると、すべての.content要素に最大の高さが与えられます。

ここで動作しています: http://jsfiddle.net/aNcYC/2/

于 2013-06-26T23:28:07.127 に答える