clientHeight/clientWidth 在不同的浏览器上返回不同的值 [英] clientHeight/clientWidth returning different values on different browsers

查看:40
本文介绍了clientHeight/clientWidth 在不同的浏览器上返回不同的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

属性 document.body.clientHeightdocument.body.clientWidth 在 IE7、IE8 和 Firefox 上返回不同的值:

Properties document.body.clientHeight and document.body.clientWidth return different values on IE7, IE8 and Firefox:

IE 8:

document.body.clientHeight : 704 
document.body.clientWidth  : 1148

IE 7:

document.body.clientHeight : 704 
document.body.clientWidth  : 1132

火狐:

document.body.clientHeight : 620 
document.body.clientWidth  : 1152

为什么会存在这种差异?
是否有不使用 jQuery 在不同浏览器(IE8、IE7、Firefox)之间保持一致的等效属性?

Why does this discrepancy exist?
Are there any equivalent properties that are consistent across different browsers (IE8, IE7, Firefox) without using jQuery?

推荐答案

这与浏览器的盒子模型有关.使用 jQuery 或其他 JavaScript 抽象库之类的东西来规范 DOM 模型.

This has to do with the browser's box model. Use something like jQuery or another JavaScript abstraction library to normalize the DOM model.

这篇关于clientHeight/clientWidth 在不同的浏览器上返回不同的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆