Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 等高脚本几乎可以工作_Javascript_Height_Equals - Fatal编程技术网

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或任何需要的

不,元素没有应用边距/填充。