4
A
回答
6
暫時show()
荷蘭國際集團檢索孩子的身高元素似乎工作確定。
HTML:
<div id="target" style="display:none;">
<!-- Add a background color to see if it's noticeable -->
<div style="height:123px; background:#000;"></div>
</div>
JS:
// Show the hidden parent of the element we want the height of
$("#target").show(0, function(){
// Find and grab the height of the element we want
the_height = $(this).find("div").height();
// Hide parent and display child's height after it
}).hide().after(the_height);
1
it's very difficult(in other word you can't)
獲取隱藏元素的高度...因爲dom doesn't consider hidden elements while rendering the page
。
1
隱藏的元素具有未定義的寬度和高度,因此無法獲取它們。
2
0
要麼你應該顯示div或不可能獲得隱藏元素的高度。我會說,使用.show()來顯示div,獲得高度,然後使用.hide()來再次隱藏它。
1
這是有點klunky,但你必須有一個對象之前,它可以呈現被測量。
var $target = $("#target");
$target[0].parentNode.runtimeStyle.display = "block";
var height = $target.height();
$target[0].parentNode.runtimeStyle.display = "none";
alert(height);
相關問題
- 1. 獲取未顯示元素的子元素的寬度/高度
- 2. AngularJS - 無法獲取元素的高度
- 3. 如何在我的場景中獲取父元素高度?
- 4. 如何獲取內部具有json元素的ArrayList的元素?
- 5. 獲取元素的寬度和高度
- 6. 獲取元素高度
- 7. jQuery獲取元素沒有顯示=「無」
- 8. 如何獲取父元素?
- 9. 如何獲取當前元素高度?
- 10. AngularJS:如何獲取元素高度
- 11. 如何獲取具有XPATH中最大子元素的元素?
- 12. 獲得元素的高度
- 13. 將元素的高度設置爲%高度的元素高度
- 14. 獲取元素的父
- 15. 獲取元素的表父
- 16. 獲取ui-view中元素的高度
- 17. 獲取元素的總高度?
- 18. 獲取兒童元素的高度
- 19. 獲取元素的完整高度?
- 20. 獲取元素高度的問題
- 21. 獲取前一個元素的高度
- 22. 獲取HTML元素的高度jQuery
- 23. 如何使用xpath獲取具有屬性的父元素
- 24. 如何增加具有絕對定位元素的元素的高度
- 25. 如何通過.get()獲取父元素一次獲取元素
- 26. 如何獲取元素的父級?
- 27. 如何獲取父元素的ID?
- 28. HTML:獲取要顯示的子元素(較低的z-index)比其父元素?
- 29. 如何使用jQuery獲取父元素的同級元素
- 30. 計算父元素的高度
+1爲一個很好的技巧...但顯示和隱藏div將導致眨眼效果。 – Vivek 2011-05-30 12:05:41
@Vivek:好像不適合我。 – Marcel 2011-05-30 12:09:18
這肯定會導致瀏覽器在舊PC上閃爍。這是因爲它會強制連續兩次完成重新佈局。我建議在依靠它之前徹底測試此解決方案。 – Exelian 2011-05-30 12:29:12