gpt4 book ai didi

javascript - 调整窗口大小时,DIV offsetWidth/Width/innerWidth 在 IE8 中返回零

转载 作者:行者123 更新时间:2023-11-28 11:35:22 25 4
gpt4 key购买 nike

我的页面中有很多元素。请考虑下面的DIV

    <div id="root">    
..................
<div id="child1">
.............
</div>
<div id="child2">
...............
</div>
</div>

根 div(#root) 在加载时根据内容有一些宽度。

当窗口调整大小时调用 repaint() 函数,它存在于窗口调整大小函数中

$(window).resize( function () {
repaint();
});
function repaint(){
//width returns "0" in IE8 browser and other browsers working fine
var width=$("#root").width() || $("#root").innerWidth() -> returns zero value in IE8
}

它在 IE8 浏览器中返回宽度为“0”,但在 IE9 或其他现代浏览器中返回一些宽度 (960px)。

我不知道这个问题的确切原因是什么。

为什么在调整窗口大小时返回零宽度。

谢谢,

湿婆

最佳答案

http://jsfiddle.net/5LFXK/

这适用于 IE8。查看控制台(布局被搞砸了)。

$(window).resize( function () {
repaint();
});
function repaint(){
//width returns "0" in IE8 browser and other browsers working fine
var width=$("#root").width();
console.log(width);

}

关于javascript - 调整窗口大小时,DIV offsetWidth/Width/innerWidth 在 IE8 中返回零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20948305/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com