使用javascript更改div上的高度 [英] Change height on div with javascript

查看:142
本文介绍了使用javascript更改div上的高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在div的高度大于100像素时设置div的高度。

I want to set the height on a div when the div is more than 100px in height.

例如,当div的内容使div的高度

For example, when the content of the div makes the div's height fill more than 100px, I want it automatically fit to 200 px.

推荐答案

您可以这样做的一种方法是确保在元素CSS中没有height属性(内联样式很好)。然后,当内容改变时调用这个函数:

One way you can do this is to make sure there is no "height" attribute in the elements CSS (inline styling is fine). Then, when the content is changed call this function:

if ($('#myDiv').height() > 100) {
    // Div is larger than 100px so increase it to 200px
    $('#myDiv').css('height', '200px');
}

这篇关于使用javascript更改div上的高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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