找出div的高度和设置div的高度 [英] Find out divs height and setting div height
问题描述
我对javascript / jquery东西很新,但我想做这样的事情:
I'm quite new to javascript/jquery stuff, but i would like to do this kind of thing with it:
我有四个div,一边这样和内容在每一个。现在如果有更多的内容,它会变得更高。我想让其他divs也很高,即使他们没有那么多的内容。所以基本上我想要脚本通过divs并检查高度,并设置所有的div高度相同的最高的div。希望你明白:)
I have four divs side-by-side like this and content in each one. Now if one has more content it gets stretched higher. I would like to make the other divs as high too even if they don't have as much content. So basically i want the script goes through the divs and check the heights and sets all of divs heights to same as the highest div has. Hopefully you understand :)
推荐答案
我在使用SLaks代码时出现NaN错误。将maxHeight的初始值设置为0即可。
I was getting a NaN error with SLaks code. Giving maxHeight an initial value of 0 did the trick.
var maxHeight = 0;
$('div')
.each(function() { maxHeight = Math.max(maxHeight, $(this).height()); })
.height(maxHeight);
感谢SLaks!
这篇关于找出div的高度和设置div的高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!