document.body.clientWidth 和 document.body.offsetWidth 有什麽區別

2003rainbow 2004-01-16 09:07:21
clientWidth 和 offsetWidth 有什麽區別

...全文
183 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
仙人掌 2004-01-16
  • 打赏
  • 举报
回复
clientWidth Property
--------------------------------------------------------------------------------
Retrieves the width of the object including padding, but not including margin, border, or scroll bar.

offsetWidth Property
--------------------------------------------------------------------------------
Retrieves the width of the object relative to the layout or coordinate parent

example:
<DIV ID=oDiv STYLE="overflow:scroll; width:200; height:100">This example shows the difference between
the dimension retrieved by the <B>clientWidth</B> and the dimension retrieved by the <B>offsetWidth</B>, the latter
including the width of scrollbars.</DIV>
<BUTTON onclick="alert(oDiv.clientWidth)">client width</BUTTON>
<BUTTON onclick="alert(oDiv.offsetWidth)">offset width</BUTTON>

DwNet 2004-01-16
  • 打赏
  • 举报
回复
在整个body窗体中.document.body.offsetWidth 比 document.body.clientWidth 多出一点儿偏移.我理解的是滚动条的宽度吧(你看右边的滚动条,在滚动条以内的就是document.body.clientWidth,加上两边的滚动条(当然有可能没有出现,如左边的),就是document.body.offsetWidth)

87,921

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧