jquery的height屬性總是返回0.我將它與Bootstrap一起使用。不確定是否會有衝突。我經歷了幾個在線推薦的解決方案,但沒有解決它。下面是代碼片段jquery height returns 0
/*html */
<div class="hidden-sm hidden-md hidden-lg" class="mobNewsEvents">
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
<h3 style="text-align: center;">Events</h3>
<div class="mobEvents"> //need to get the height of this div element
<ul>
<li>...</li>
</ul>
</div>
</div>
</div>
</div>
/*script*/
(function($){
$(window).load(function(){
var temp = $('.mobEvents').height();
alert(temp);
});
})(jQuery);
是div'hidden'作爲'class'值建議?那麼它的高度是* 0. – Bergi
謝謝Bergi。我正在深入研究。你可能是對的。會讓你知道這是否修復它。 – Ram
是的,它是除了我忘記注意到的顯示屬性之外的其中一個父類的顯示屬性。感謝您的幫助 – Ram