- dom.style.width/height(只适用获取内联元素的宽和高)
- dom.currentStyle.width/height(获取渲染后的宽高,但是仅IE支持)
- window.getComputedStyle(dom).width/height(与2原理相似,但是兼容性,通用性会更好一些)
- dom.getBoundingClientRect().widht/height(计算元素绝对位置,获取到四个元素left,top,width,height)
JS如何设置获取盒模型对应的宽高
最新推荐文章于 2024-04-12 16:46:15 发布
本文介绍了四种获取HTML元素尺寸的方法:使用`dom.style`获取内联样式宽度和高度;利用`dom.currentStyle`获取渲染后的尺寸(仅IE支持);通过`window.getComputedStyle`获取兼容性更好的元素尺寸;运用`dom.getBoundingClientRect`计算元素绝对位置。
3974

被折叠的 条评论
为什么被折叠?



