FireFox 中的 clientHeight

发布于 2024-10-18 04:52:23 字数 217 浏览 12 评论 0原文

我有一个 HTML 代码表格。

我需要使用 JavaScript 获取该表的高度,因此

alert(document.getElementById('myTable').clientHeight);

在 IE 中返回正确的值,但在 FF 中始终返回 0。

如何获取 Firefox 中表格的高度?

谢谢!

I have a table in HTML code.

I need to get height of that table using JavaScript, so

alert(document.getElementById('myTable').clientHeight);

returns a correct value in IE, but always returns 0 in FF.

How can I get the height of the table in Firefox?

Thanks!

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

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

发布评论

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

评论(4

鱼忆七猫命九 2024-10-25 04:52:23

MDC 说:

clientHeight 是 Internet Explorer 对象模型中引入的非标准、特定于 HTML 的属性。

在 Firefox 中, offsetHeight 属性包含当前像素元素的高度,因此您可以使用以下内容:

var theHeight = element.clientHeight || element.offsetHeight;

MDC says:

clientHeight is a non-standard, HTML-specific property introduced in the Internet Explorer object model.

In Firefox, the offsetHeight property contains the current pixel height of an element, so you can use something like:

var theHeight = element.clientHeight || element.offsetHeight;
迟月 2024-10-25 04:52:23

你尝试过offsetHeight吗?请参阅http://www.quirksmode.org/dom/w3c_cssom.html

Did you tried offsetHeight? See http://www.quirksmode.org/dom/w3c_cssom.html

自由如风 2024-10-25 04:52:23

clientHeight 在我的 Firefox 中工作: http://jsfiddle.net/sZ9eg/

clientHeight works in my Firefox: http://jsfiddle.net/sZ9eg/

奶气 2024-10-25 04:52:23

也许 comeone 可以在这里纠正我,但是如果您想获取特定元素的高度,那么为什么不直接使用

EDIT:这仅在元素具有内联样式和定义的高度时才有效

document.getElementById('myReputation').style.height;

Maybe comeone can correct me here, but if you want to get the height of a specific element then why not just use

EDIT: this only works if the element has inline styles and a defined height

document.getElementById('myReputation').style.height;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文