3
1.4.4隱藏元素的返回大小,但是另一個隱藏元素中的元素呢? 有沒有更好的解決方案,然後getWidth?如何獲取隱藏父元素的大小?
<script type="text/javascript">
function getWidth(element){
var parent = element.parent();
$('body').append(element);
var width = element.width();
parent.append(element);
return width;
}
$(function(){
var width = $("#foo").width();
console.log(width); //0
width = getWidth($("#foo"));
console.log(width); //ok
});
</script>
<div style='display:none'>
<div style='display:none' id='foo'>bar</div>
</div>
請參閱http://stackoverflow.com/questions/1841124/find-the-potential-width-of-a-hidden-element – Flo 2010-12-20 09:14:47