Javascript 等高脚本几乎可以工作
我用它来平衡两根柱子的高度:Javascript 等高脚本几乎可以工作,javascript,height,equals,Javascript,Height,Equals,我用它来平衡两根柱子的高度: function equalheight(one, two) { if (document.getElementById(one)) { var lh = document.getElementById(one).offsetHeight; var rh = document.getElementById(two).offsetHeight; var nh = Math.max(lh, rh);
function equalheight(one, two) {
if (document.getElementById(one)) {
var lh = document.getElementById(one).offsetHeight;
var rh = document.getElementById(two).offsetHeight;
var nh = Math.max(lh, rh);
document.getElementById(one).style.height = nh + "px";
document.getElementById(two).style.height = nh + "px";
}
}
window.onload = function () {
equalheight('primary', 'secondary');
}
。。。它工作得很好,除了最高柱子的高度进一步增加了4-5倍,这是不需要的。为什么它不能准确地计算出最高柱子的高度
谢谢,因为它包含了任何填充。通过读取并减去它的值,或者使用
var nh = Math.max(lh, rh) - 4;
或5或任何需要的 不,元素没有应用边距/填充。