使用纯 JavaScript 获取 PHP 生成的 div 的高度
我一直在尝试计算使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
element.offsetHeight
- 偏移高度不是样式信息的一部分。element.offsetHeight
- the offset height is not a part of the style information.element.clientWidth 也可能有用。
element.clientWidth might also be useful.