使用javascript设置max-height [英] Set max-height using javascript

查看:3580
本文介绍了使用javascript设置max-height的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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屋!

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