使用javascript设置max-height [英] Set max-height using javascript
问题描述
我有一个div,这个div的最大宽度是用户定义的。我知道我可以使用element.style.height,但这不工作在IE。
任何想法如何实现max-height等效的Firefox通过使用javascript?
通常,样式属性名称通过删除连字符和驼峰文字而转换为JavaScript属性名称。 / p>
因此 background-color
变成 backgroundColor
, text-align
变为 textAlign
和 max-height
变为 maxHeight
。
您可以设置元素 el
mHeight
由:
el.style.maxHeight = mHeight;
请记住对 mHeight
使用有效的值。
I have a div, and the maximum width for this div is user defined. I know I can get it done using element.style.height but this doesn't work in IE.
Any ideas on how to implement the max-height equivalent of Firefox by using javascript?
Usually style attribute names are translated into javascript property names by removing the hyphens and camelcase the name instead.
So background-color
becomes backgroundColor
, text-align
becomes textAlign
and max-height
becomes maxHeight
.
You can set an element el
's maximum height to mHeight
by:
el.style.maxHeight=mHeight;
Remember to use a valid value for mHeight
.
这篇关于使用javascript设置max-height的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!