【发布时间】:2013-07-08 05:31:33
【问题描述】:
据我所知,DOM 元素 style 的 CSS 属性是驼峰式大小写的,因此 min-height 将是 element.style.minHeight,但在我下面的示例中,样式属性为空,但 jQuery 的抽象得到了它正确。
// element with css: #test{ min-height: 100px; }
var el = document.getElementById('test');
console.log( el.style.minHeight );
// ""
console.log( $(el).css('min-height') );
// "100px"
See fiddle for this in action.
jQuery 做了什么来提取我没有做的正确样式属性?
有趣的是,直接在html元素does work上添加样式属性。
【问题讨论】:
-
看起来这是
getComputedStyle的情况,但由于样式直接应用于元素而不是继承,我不明白为什么需要这样做。 -
—— style 属性指的是内联样式,而不是样式表(继承的或其他的)。
标签: javascript jquery dom styles