jQuery 的 .width()
、jQuery 的 .css('width')
和 .style 返回的值有什么区别.width
节点上的属性?
我很好奇,因为在尝试将两个表格单元格的宽度设置为相等时,前两个给了我同样的错误答案。它们实际测量的是什么,为什么它与我在浏览器中查看元素时在 .style
属性中看到的值不同?
最佳答案
来自 width
官方文档
The difference between .css(width) and .width() is that the latter returns a unit-less pixel value (for example, 400) while the former returns a value with units intact (for example, 400px). The .width() method is recommended when an element's width needs to be used in a mathematical calculation.
我会说 .css('width')
之间没有区别和 .style.with
作为css()
方法用于设置样式对象属性。
.css('width')
之间的区别/.width()
和 .style.with
是 jQuery 方法使用 window.getComputedStyle( elem, null )
获取计算样式.此方法用于在应用 CSS 和样式后读取实际属性。
关于javascript - jQuery .width()、style.width 和 jQuery .css ('width' 之间有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17494906/