如何确定字段集边框的高度和宽度?

发布于 2024-10-07 19:21:50 字数 192 浏览 0 评论 0原文

我有一个字段集,我想在 JavaScript 中确定顶部(包括图例)和底部边框的高度(厚度),以及左侧和右侧边框的宽度。

我正在尝试调整位于字段集中的 JavaScript 表的大小,以便字段集 + 表的大小适合页面上的特定区域。如果我将表设置为区域的尺寸,则字段集+表组合对于该区域来说太大,因此我需要减去字段集边框占用的空间。

谢谢。

I have a fieldset and I'd like to determine in JavaScript the height (thickness) of the borders at the top (including the legend) and bottom, also the width of the borders on the left and right.

I'm trying to resize a JavaScript table located in the fieldset so the fieldset + table are sized to fit in a particular area on the page. If I set the table to the dimensions of the area then the fieldset+table combo is too large for the area, so I need to subtract the space the fieldset border is taking up.

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云胡 2024-10-14 19:21:50
var fieldset = document.getElementsByTagName("fieldset")[0];
alert(getStyle(fieldset, "borderTopWidth"));
alert(getStyle(fieldset, "paddingTop"));

//http://www.quirksmode.org/dom/getstyles.html
function getStyle(el,styleProp)
{
    if (el.currentStyle)
        var y = el.currentStyle[styleProp];
    else if (window.getComputedStyle)
        var y = document.defaultView.getComputedStyle(el,null).getPropertyValue(styleProp);
    return y;
}
var fieldset = document.getElementsByTagName("fieldset")[0];
alert(getStyle(fieldset, "borderTopWidth"));
alert(getStyle(fieldset, "paddingTop"));

//http://www.quirksmode.org/dom/getstyles.html
function getStyle(el,styleProp)
{
    if (el.currentStyle)
        var y = el.currentStyle[styleProp];
    else if (window.getComputedStyle)
        var y = document.defaultView.getComputedStyle(el,null).getPropertyValue(styleProp);
    return y;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文