<div class="t_header t_header_right" style="margin-bottom: 5px;">
<span>用户</span>
</div>
去掉单位"px",可以使用JavaScript的字符串处理方法来实现。可以使用parseInt()函数将字符串转换为整数,然后再将其转换回字符串。以下是一个示例代码:
let headerRight = document.getElementsByClassName("t_header_right")[0];
let headerRightHeight = headerRight.offsetHeight;
let marginBottom = headerRight.style.marginBottom;
let marginBottomWithoutPx = parseInt(marginBottom) + "px";
在上述代码中,marginBottom是一个带有"px"单位的字符串,parseInt()函数将其转换为整数,然后再通过字符串拼接将其转换回带有"px"单位的字符串。
文章介绍了如何使用JavaScript的parseInt()函数来处理带有px单位的CSS样式属性,例如marginBottom,将字符串值转换为整数后,再拼接回px单位的字符串形式。
222

被折叠的 条评论
为什么被折叠?



