問題已修改。 對象對象是我的錯。使用JQuery獲取DIV的高度
我想檢測一些div的高度,然後將該值分配給另一個div。
但我寫的代碼並沒有給我一個正確的答案(我對Javascript/Jquery不太好)。
The CSS & HTML僅用於演示目的。
我想給我的.iframe
類留下空間高度,但使用jquery/Javascript。
我的結構幾乎相似,並且container
width
是流動的。
$(document).ready(function() {
var lhs = $('.section-updates').parent().outerHeight();
console.log(lhs);
var rhs = $('.customer-focus').parent().height(lhs);
console.log(rhs);
var cfH = $('.customer-focus').outerHeight();
$('.iframe').height(rhs - cfH);
});
.section-updates {
height: 500px;
width: 50%;
background: purple;
float: left;
}
.customer-focus {
height: 200px;
background: yellow;
float: left;
width: 50%;
}
.iframe {
min-height: 100px;
background: tomato;
float: left;
width: 50%;
}
.container {
width: 95%;
height: 100%;
margin: 0 auto;
overflow: hidden;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="container">
<div class="section-updates"></div>
<div class="customer-focus"></div>
<div class="iframe"></div>
</div>
jQuery的'高度(值)'函數返回一個jQuery對象,請參閱[文檔](http://api.jquery.com/height/#height2) –
我認爲.height()是隻讀的,因此你的行啓動'var rhs'是不合法的。 –
可以多個參數傳遞給'的console.log(「LHS --------:」,左圖);' – Satpal