原生js如何获取某一元素的高度

一般有三种方法:

1.document.getElementById("id").style.height,这种方法的前提是必须之前已经显示的在css中声明过height,才能取得正确的值

2.document.getElementById("id").clientHeight

3.document.getElementById("id").offsetHeight


发布了30 篇原创文章 · 获赞 6 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/qq_21901233/article/details/78646300