日期:2014-05-16  浏览次数:20351 次

offsetWidth的浏览器兼容问题。
offsetWidth在IE和火狐上都正常,能正常控制宽度。

但是在Chrome(谷歌浏览器)和遨游浏览器上用JS的offsetWidth来控制宽度时,控制不了,页面上的宽度是0.

急,求解,在线等...



------解决方案--------------------
你怎样获取的?
------解决方案--------------------
根据这个自己改吧~!
JScript code

function getWindowSize() {
    if (self.innerHeight) { // WEBKIT
        return { 'width':self.innerWidth, 'height':self.innerHeight };
    } else if (document.documentElement && document.documentElement.clientHeight) { // IE standards 模式
        return {
            'width' :document.documentElement.clientWidth,
            'height':document.documentElement.clientHeight
        };
    } else if (document.body) { // IE quirks 模式
        return {
            'width' :document.body.clientWidth,
            'height':document.body.clientHeight
        };
    }
}

------解决方案--------------------
探讨

引用:

你怎样获取的?


用innerHTML输出。

------解决方案--------------------
楼主把完整的代码 贴出来,如果很多,那么模拟一个页面出来,大家好调试
------解决方案--------------------
在jquery低版本中不支持innerHeight
------解决方案--------------------
我之前也遇到类似的问题。
JQ加载了两个层,由于css的z-index值设置,导致无法取到相对于父窗口的偏移量。
------解决方案--------------------
如果不是浏览器兼容的问题,
请检查一下css文件的display和z-index设置。