gpt4 book ai didi

jquery - .width() 函数没有返回正确的值

转载 作者:太空狗 更新时间:2023-10-29 14:03:02 24 4
gpt4 key购买 nike

我正在尝试使用 .width() 通过 jQuery 动态访问元素的宽度。在开发人员工具中,我可以看到元素的宽度为 37.333Px,而 .width() 给出 38.33334Px。

开发者工具中的宽度

enter image description here

宽度来自 .width()

enter image description here

在这种情况下差异是 1px,但有时差异是小数。为什么会有这样的差异?我哪里错了?有没有其他的可以得到精确的宽度。

最佳答案

我们可以通过下面列出的几种方法来获取宽度,

width() - 设置或返回元素的宽度

innerWidth() - 返回元素的宽度(包括填充)

outerWidth() - 返回元素的宽度(包括填充和边框)。

outerWidth(true) - 返回元素的宽度(包括填充、边框和边距)。

enter image description here

enter image description here

关于jquery - .width() 函数没有返回正确的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35334023/

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