使用纯 JavaScript 获取 PHP 生成的 div 的高度

发布于 2025-01-01 04:00:30 字数 501 浏览 3 评论 0原文

我一直在尝试计算使用 PHP-MySQL 生成的除法的高度,但找不到任何有效的方法。我真的很想用纯 javascript 来做这件事,因为我根本不喜欢 jQuery。我尝试了 element.style.height 和 element.style.height() 以及 element.style.offsetHeight 甚至 element.currentStyle (或 W3C 浏览器的 window.getCompulatedStyle)。

但没有任何作用。有很多帖子,但似乎没有一个建议有效。我真的不知道该再尝试什么...请不要建议 jQuery 解决方案,因为我刚刚尝试了 $('#element').height() 和 $('#element').outerHeight(),但都不起作用。实际上可能吗?该除法以一系列命令的形式输出,例如

echo ('<div id="myDiv">...</div>');

“我希望有人可以帮助我”,它使我完全陷入停滞。

I have been trying to calculate the height of a division which I generated using PHP-MySQL and can't find anything that works. I'd really like to do it in pure javascript since I don't get on with jQuery at all. I tried element.style.height and element.style.height() and also element.style.offsetHeight and even element.currentStyle (or window.getComputedStyle for W3C browsers).

Yet nothing works. There are a lot of posts but none of the advice seems to work. I really don't know what to try any more...please don't suggest a jQuery solution since I just tried $('#element').height() and $('#element').outerHeight(), and neither worked. Is it actually possible? The division is output as a series of commands such as

echo ('<div id="myDiv">...</div>');

I hope someone can help me with this, it's brought me to a complete standstill.

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

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

发布评论

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

评论(2

为你鎻心 2025-01-08 04:00:30

element.offsetHeight - 偏移高度不是样式信息的一部分。

element.offsetHeight - the offset height is not a part of the style information.

酒与心事 2025-01-08 04:00:30

element.clientWidth 也可能有用。

element.clientWidth might also be useful.

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