我想找到环绕几行的 SPAN 的总宽度。那可能吗?它是单个 SPAN 标记,没有其他内部节点...
如果不可能,我至少想找到 SPAN 开始和结束的左右像素偏移。
最佳答案
嗨, 我认为您可以通过使用 getBoundingClientRect 函数来实现这一点。
var leftPosition = yourElement.getBoundingClientRect().left;
var rightPosition = yourElement.getBoundingClientRect().right;
var topPosition = yourElement.getBoundingClientRect().top;
var bottomPosition = yourElement.getBoundingClientRect().bottom;
我不确定您是否正在寻找这个。
关于javascript - 包裹内联元素的总宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/994480/