不折腾会死星球欢迎您的加入!

jquery让两个DIV自适应高度

代码如下,对比两个DIV的高度哪个高度高就调整另一个DIV的高度对其一致。这个DIV的作用比如我现在用的模板边栏和右边内容 中间是一条边界线,边界线我只用了一边,另一边如果高度不一致将会导致边界线有部分不显示。这时候下边代码就派上用场了。

<script type="text/javascript">function $(id){return document.getElementById(id)
}function getHeight() {if ($("blog-offcanvas").offsetHeight>=$("blog-right").offsetHeight){
$("blog-right").style.height=$("blog-offcanvas").offsetHeight + "px";
}else{
$("blog-offcanvas").style.height=$("blog-right").offsetHeight + "px";
}
}
window.onload = function() {getHeight();
}
</script>