根据文档,innerWidth 几乎可以满足我的需要:
"Gets the inner width (excludes the border and includes the padding) for the first matched element."
我需要知道宽度不包括 填充。 IE。元素内的可用空间。
jquery 是否提供类似这样的东西 - 进行了一些谷歌搜索,但找不到任何解决方案。
我考虑过从内部宽度中减去 padding-left
和 padding-right
值 - 但考虑到这些可能是百分比、像素或 em 我不是确定这是否可靠。
有什么建议吗?
最佳答案
您可能只是在寻找 width() 函数..
查看文档,它排除了填充:http://api.jquery.com/width/
(正如现代浏览器对 css 宽度属性的表示所预期的那样)
编辑:现在是 2012 年,jQuery 1.8 刚刚发布。虽然这仍然相关,但您可能还想阅读 following article from the jQuery blog关于 1.8 版中的 box-sizing
注意事项
关于javascript - jQuery 如何获得 innerWidth 但没有填充?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7567915/