如何检测元素是否具有“自动”高度 [英] How to detect if element has 'auto' height

查看:126
本文介绍了如何检测元素是否具有“自动”高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

window.getComputedStyle(element).height element.clientHeight 都返回元素的当前高度

Both window.getComputedStyle(element).height and element.clientHeight are returning the current height of the element in pixels, regardless of the value set in the CSS.

有什么方法可以找出高度是否设置为 auto 或像素以外的其他单位?

Is there any way to find out if the height was set to auto, or other units than pixels ?

@pvnarula通过他链接的页面建议的一个解决方案是暂时更改元素的内容,然后比较高度
一点点黑客...

One solution that @pvnarula suggests through the page he linked is to temporarily change the contents of the element, then compare heights. A little bit hacky...

推荐答案

请尝试:

document.getElementById("ele_id").style.height


$ b b

同时检查下面的插件:

Also check the following plugin:

http://gregpettit.ca/2012/jquery-check-if-element-has-auto-widthheight/

这篇关于如何检测元素是否具有“自动”高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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