gpt4 book ai didi

javascript - 获取 p 标签的行高

转载 作者:太空狗 更新时间:2023-10-29 12:31:19 25 4
gpt4 key购买 nike

<分区>

我想计算出 <p> 的行高div 内的标记。

var myp = document.getElementById('myp');
var heightLabel = document.getElementById('heightLabel');
heightLabel.innerHTML = myp.style.lineHeight + " is the height.";
    <div> 
<p id=myp>People assume I'm a boiler ready to explode, <br>but I actually have very low blood pressure, <br>which is shocking to people.</p>
</div>

<h3 id="heightLabel"></h3>

但是,如上面的代码所示,如​​果未明确指定 p 标签的行高,则使用 .style.lineHeight返回空字符串。

有什么方法可以得到 <p> 中一行的高度吗?如果尚未分配标签?我想在最后以 px 为单位获取它。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com